The ECS Architecture - Performance in UE4

  Рет қаралды 19,085

Dennis Andersson

Dennis Andersson

Күн бұрын

Brief overview of Entity Component Systems in game development and a demo of such system in Unreal Engine 4.
0:00 Introduction
0:19 Understanding the Problem
3:24 The ECS Architecture
7:56 Why Care?
9:34 Proof of Concept
11:17 The Code
14:08 Conclusions
#UE4 #ECS #GameDev
// ~~
Marketplace assets used in the Demo
www.unrealengine.com/marketpl...
// ~~
References and Sources
Scott Meyers: Cpu Caches and Why You Care
• code::dive conference ...
CppCon 2014: Mike Acton "Data-Oriented Design and C++"
• CppCon 2014: Mike Acto...
Data-Oriented Design (Or Why You Might Be Shooting Yourself in The Foot With OOP)
gamesfromwithin.com/data-orie...
Overwatch Gameplay Architecture and Netcode
• Overwatch Gameplay Arc...
Aggregating Ticks to Manage Scale in Sea of Thieves | Unreal Fest Europe 2019
• Aggregating Ticks to M...
CppCon 2018: Stoyan Nikolov “OOP Is Dead, Long Live Data-oriented Design”
• CppCon 2018: Stoyan Ni...
Speeding up Game Logic in Unreal Engine
• Speeding up Game Logic...
// ~~
Other clips used in the video
Next-Gen Games Sizzle Reel | December 2020
• Video
Unreal Engine 5 Revealed!
• Unreal Engine 5 Reveal...
// ~~
Twitter: / mazymodz
Discord: MazyModz # 3946

Пікірлер: 56
@dennis_aaa
@dennis_aaa 3 жыл бұрын
This is only a very brief overview of the ECS and Data-Oriented-Design. There are lots of resources in the description by people much smarter than me who go into more detail. I can't recommend watching those enough.
@kingman1012
@kingman1012 11 ай бұрын
Just found your channel today and all of the content I've seen so far has been incredibly informative. Thank you for inspiring me to keep on learning!
@onerimeuse
@onerimeuse Жыл бұрын
I've watched probably every single other ECS and Data Oriented Programming video on youtube up until this point, but if I'd have found yours earlier I wouldn't even have needed to watch the others. This is by far the best breakdown I've seen. Great examples, and thank you for showing the code and breaking it down to chunks and explaining those. I'm so lucky I started learning programing and discovered this concept early... I honestly always just assumed that programming systems and components were how games worked. Not with those words, but in my mind, having a whole chunk set aside that tells everything how to move or whatnot just makes so much sense. It seems insanely convoluted to need to "teach" every single thing in a game how it works. I only recently learned about the idea of inheritance, and that just makes everything even crazier to me! How has this been the norm for as long as it has? It blows my mind. lol
@richardtoth7240
@richardtoth7240 Жыл бұрын
Thank you so much for this video. I actually never even considered optimising for cache until now. I hope we'll see more videos like this from you in the future.
@brannonharris4642
@brannonharris4642 3 жыл бұрын
One of the best game dev videos on the internet right now. Well done, lad
@volodymyrbarannik179
@volodymyrbarannik179 3 жыл бұрын
This is literally the best video on ECS ever made. Thank you so much! Can't wait to see (and use) your ECS library for UE4. (dude, make it open-source, there are plenty of potential contributors out there!!!!)
@gostan2718
@gostan2718 3 жыл бұрын
Nice. Very informative. Subscribed
@musikalniyfanboichik
@musikalniyfanboichik 3 жыл бұрын
great video, thanks
@darkbibni
@darkbibni 8 ай бұрын
And now we got MassEntity! Thanks for this video!
@2danimm
@2danimm 6 ай бұрын
thanks, this is really helpful
@embeddedbastler6406
@embeddedbastler6406 2 жыл бұрын
Data oriented design is just so logical. It's almost like when we've programmed in OOP the whole time, we tried to ignore the actual problem of transmuting data and instead focused on structuring the code with inheritance patterns, no matter if this would actually help to solve the problem. Just because someone once said that software should be written using OOP.
@Donnirononon
@Donnirononon 3 жыл бұрын
Great Video! Your speed of talk and voice is slightly sleep inducing but i really enjoyed that only important information and examples are shown, no unecessary intro to waste time or unrelated info. Great Job, thumb up.
@JohnSmith-ox3gy
@JohnSmith-ox3gy 3 жыл бұрын
Atleast it wasn't a 2 hour long video. Pro tip: This is exactly what the youtube playback speed is for.
@Piratehurrdurr
@Piratehurrdurr Жыл бұрын
Much appreciated! One question I struggle with is how entities bunch their components together, now I understand that to get each Move+Location component you have to iterate over several lists as they're grouped by archetype.
@VladMihailescu
@VladMihailescu 2 жыл бұрын
Hi, awesome video, was also thinking about this and am curios where we can find your library, also consider open sourcing it as it can benefit it's development greatly.
@velikiy-prikalel
@velikiy-prikalel 2 жыл бұрын
you can find the ecs plugin apparatus in marketplace
@VladyVeselinov
@VladyVeselinov 2 жыл бұрын
Instant subscribe
@KonradGM
@KonradGM Жыл бұрын
anyobdy able to explain to me what the FQuery or Query in this code example is? Is it UE thing or something custom they made?
@YawLighthouse
@YawLighthouse 3 жыл бұрын
This is a fantastic explanation of ECS and an implementation of it inside an existing codebase that isn't built for it, thank you! I did have a few questions that the code explanation didn't really cover in detail that I think would have helped with explaining it more. 1) This is just to confirm it incase I'm misunderstanding, when your implementing into the actor in this case your getting a template of specific components(I'm assuming if the template doesn't already exist and if it does then just gets it from the existing list of archetypes that were created at runtime) and then creating a generic entity class that is intended to work with that archetype, then you setup the components in that entity(that part I understood) and then once its ready, tell the archetype that this entity is part of that list of entities and that it should be updated and such? 2) Where did the system's part of the ECS actually get updated? The code example didn't show where that stuff actually gets used outside of what the systems would be doing inside it. Again a fantastic video, I know asking to see the source code would be a bit much(assuming the project is probably super messy or whatever) but if its possible that would definitely go a long way as well because ECS definitely sounds like a great new tool to use...
@dennis_aaa
@dennis_aaa 3 жыл бұрын
GetArchetype gets or creates a new "database table" for the specific components. The Entity is just a unique ID and not a class. The CreateEntity function just returns the first free entity id in the pool, and AddEntity is to add a new row into the archetype database with new data for that entity id. Systems are updated through a Scheduler, it basically has a single FTickFunction for each ETickingGroup. A system class is registered to one of those tick functions and when executed it just loops over all registered systems and calls Update on them. A bit hard to release the source ATM, this is only a MVP and there are lots of features I want implemented before I can consider releasing it (Multithreading, networking, blueprints etc.)
@YawLighthouse
@YawLighthouse 3 жыл бұрын
@@dennis_aaa Ah ok thank you, so that answers my question regarding the entity. But for the Systems, like are you registering them to the Scheduler inside the Scheduler, or using some sort of data asset to list them out and have the Scheduler read from it initially and setup the System to their corresponding tick function or something? I guess the basic version of what I'm asking is, I have a System I've made and now what's the process of hooking it up to the Scheduler so it can update? I really appreciate you answering my questions, if you ever do release the source code(no rush btw) probably having this Boids example as a "Simplified Version(or Branch)" without all the other bells and whistles would probably help others with understanding it easier as a learning resource...
@dennis_aaa
@dennis_aaa 3 жыл бұрын
@@YawLighthouse As of now systems are manually registered in a custom derived scheduler class unique for each project. I am not happy with this current setup and would like to automate it in the future which is why I didn't go into much detail about it
@YawLighthouse
@YawLighthouse 3 жыл бұрын
@@dennis_aaa Ah gotcha, again I appreciate you answering my questions. Everytime I looked into a simple implementation of EQS in C++ to learn from I would always be pointed to use Flecs instead of just something to learn from(so if I need to make my own implementation I have the knowledge to do so sort of thing) so you answering questions and providing a barebones explanation helped alot! :)
@refusalspam
@refusalspam 6 күн бұрын
How would you integrate something like an oct-tree or bsp-tree into your example to speed up the n^2 operation of finding the nearby boids. How would that fit into ECS?
@dennis_aaa
@dennis_aaa 6 күн бұрын
In this example I just used a grid to solve this which is very friendly to ECS. I have never had to implement an Oct-Tree or BVH etc. with ECS before so I can't comment on it. But different problems require different solutions so it's possible ECS is not a good fit for this
@BlazPecnikCreations
@BlazPecnikCreations 2 жыл бұрын
How does caching work when it comes to systems that operate on multiple components? 6:25 // movement system example foreach eid in entities: LocationComponent[eid].x += MovementComponent[eid].x; LocationComponent[eid].y += MovementComponent[eid].y; ... Do you get a cache miss in this case? How does the cpu have both LocationComponents and MovementComponents in the cache line? I hope its not a stupid question, i just can't wrap my head around this.
@dennis_aaa
@dennis_aaa 2 жыл бұрын
It depends. Firstly how the ECS is designed, is it using large mega component arrays for the program, does it group single components as tuples or does it use an archetype system as in unity? But in general though, you probably have components in L2 or L3 cache which still helps iteration time with multiple components
@DevGods
@DevGods Жыл бұрын
What type of games will benefit from ECS? How does it work in networked games? I have so many questions. But a 3x performance increase on a boid system seems like only scratching the surface. I’ve just been using OOP for so long I can’t think of places to use this!
@dennis_aaa
@dennis_aaa Жыл бұрын
You can use ECS is all types of projects, even outside of games. Though it's a tool and not a magic wand, you have to know when using it will help you or if it'll just make things more complex. For example, if you have lots and lots of players or AI that use the character movement then it might be worth exploring an ECS way of handling capsule movement. But if you don't have lots of entities that are using capsule movement then using OO might be the best way of solving that problem
@nelthy1127
@nelthy1127 Жыл бұрын
I feel my brain growing
@tomwhitcombe7621
@tomwhitcombe7621 3 жыл бұрын
Have you 4k unreal actors that are updated in your last system? If so that's likely going to be a huge bottleneck. AActor is 800 bytes without any user data, and they'll be scattered all over memory. Have a look at perhaps having one actor with the instanced static mesh (or hierarchical variant) component. Good overview. Nice work.
@JohnSmith-ox3gy
@JohnSmith-ox3gy 3 жыл бұрын
Actually the component data can be better allocated to reduce this scattering. It is one of the requirements for having thousands of actors active in a scene.
@NewkTube
@NewkTube 3 жыл бұрын
Is it possible to do and ECS like system with actor components in bp?
@JohnSmith-ox3gy
@JohnSmith-ox3gy 3 жыл бұрын
That would require a complete rework of blueprints.
@VladislavTurbanov
@VladislavTurbanov 2 жыл бұрын
You can do it in Apparatus ECS.
@deusxyz
@deusxyz 3 жыл бұрын
This is interesting, 3 times faster, I must admit it's alot faster using unitys ecs systems, maybe its burst as well, or the way they store stuff, not sure. But good to know there are ways to implement similar approaches in other engines.
@bulentgercek
@bulentgercek 2 жыл бұрын
Fast compared to what? Are you saying that you wrote the whole program exactly in Unity again and it's fast? Forget the comparisons now. I am using both of them. Unity is smaller than Unreal. I'm not talking about speed. Unity still growing as a package. They take the things that Unreal has for years, from those the individuals and companies who have been on the market for years, and include them in the system. The important thing is which package is more suitable for style and production conditions? This is how product selection is made.
@ollllj
@ollllj 2 жыл бұрын
"performance boost" = you can easily have 100 to 10000 as many simulated assets/agents, actng independently, fulfilling indepentend "scedules/jobs" , with ecs. The upper bound is mostly set by the ammount if cpu cache, and the slow ram+mainboard is less bottlenecking. This is very useful for simulation games (with large populations like Tropico that are composites of lists of traits/states, following basic needs and scedules), citybuilders (anything adjacent to dwarf fortress), anything adjacent to factorio, and the general RTS genre will easily lose its [200 units per faction limit] just by using ecs. You likely want to simplify pathfinding by precomputing and storing distance-fields to common/central rooms/doors/signposts on the gpu, and doing a* pathfinding only on the gpu, or by doing the timberborn-district-constrain, even only in a soft-version by using doors and gareways like pseudo-district-borders, and buffering distanceFields to all the doors/gates, so that any agent can easily triangulate its position in a maze, by just loading 3 (or more) relevant distance-field maps, that instantly tell the direction to 3 doors (gpus are super fast at estimating the first derivative for a general direction for a shortest path), and that gives a VERY good a* hint to where anything may be, within segments of 1024x1024 pixels. All this is the reason, I bought a ryzen9 with a gtx 3080, that underclocks even the slowest avalable 32 gb ram to run at only 2900ish ghz. I bought a pc, optimized for ECS, and it almost looks like the slow and small mainboard is an insult to all the things connected to it.
@lookitsbenji966
@lookitsbenji966 Жыл бұрын
8:54 I feel attacked. This sums up my situation completly. When i noticed many instances of an object were running at the same time, i turnt to Multithreading, and now my code looks totally unrecognisable to the begining with iterations of code that still arent anywhere close to working consistently! Ive stuck on this same issue for months.
@leroy2311
@leroy2311 2 жыл бұрын
Is this basically the same as the MassEntity system in UE5?
@dennis_aaa
@dennis_aaa 2 жыл бұрын
Yes
@shannenmr
@shannenmr 2 жыл бұрын
What do you think of MASS (ECS) in UE5 :) ?
@dennis_aaa
@dennis_aaa 2 жыл бұрын
Video coming soon
@momomadi2
@momomadi2 Жыл бұрын
@@dennis_aaa define soon Now hehehe
@gandev5285
@gandev5285 Жыл бұрын
@@dennis_aaa Can't wait
@hanyanglee9018
@hanyanglee9018 Жыл бұрын
What esc may require the most, is probably, the docs.
@Nerthexx
@Nerthexx 2 жыл бұрын
The two problems that I see with ECS are: - If you have, for example, 100 entities (minecraft skeletons, for example), where each entity has 10 components, and you have 10 systems to process these components, you would have to iterate 1000 (or 10 * 100) times, or, in other words, iterate over each entity 10 times instead of just 1 time with basic update() OOP design. So, you trade cache misses for 10 times the iteration? Doesn't seem fast to me. - If you have systems that target multiple (or even 2) components, this defeats all benefits from cache locality, making it as slow as OOP, maybe even slower (arguably).
@lekretka
@lekretka 2 жыл бұрын
Your conclusion just seems wrong. This was already tested many times in different frameworks and the ECS is inherintly faster than OOP. You literally take only data you need and process it all in one system one time per frame, instead of taking objects scattered in heap and call object.UpdateYourOwnData().
@Nerthexx
@Nerthexx 2 жыл бұрын
@@lekretka There are several problems with that logic: 1 - ECS is not cache-friendly by default. You can allocate your components in heap wherever you want and it will be as bad as "OOP". 2 - OOP is not that bad, big classes are bad. You can allocate your "small" objects (or components in component based system) using a pool or something similar, and it can be as cache-friendly as you want. Yes, there's a thought that systems in ECS allow processing the only data you need (since components of same type are allocated as big blocks), but that also requires more iteration, which require more cycles to process (I know, computer performance is not all about cycles, but still), but that also a dellusion, since most ECS systems actually work with more than one, or even multiple component types (practical example - Overwatch presentation about netcode and ecs), in which case, CPU will struggle, since components most likely will be in different heap locations, and it will be a much better option to just process blocks of OOP objects. I'm not against ECS, just watned to make that clear.
@watermelonpuppet3963
@watermelonpuppet3963 2 жыл бұрын
I'm also wondering why we could get performance benefit from ECS because of reduced cache miss. IMHO I think one system only touch one component sounds too perfect to me. Even though one type of the components can be put together and reduce cache miss, while cross referencing different types of components is still causing cache miss. However I do think ECS, meaning composition over inheritance (making data structure reusable) and separation between system (logic) and components (data), is making my head more clearer while implementing game. And it seems that it is very easy to run multi-threaded, which ultilizes the full power of a multi-core CPU.
@BigChiken44
@BigChiken44 3 жыл бұрын
Soooo ECS is very inconvinent, but can boost your perfomance if you have a lot of actors/objects? That sounds like something for extreme rare cases. I mean it's a great thing, but in 95% you don't need that. If you have 10 characters in your level, you don't need to hurt your brain trying to make ECS - instead just use nomal human OOP and voila!
@JohnSmith-ox3gy
@JohnSmith-ox3gy 3 жыл бұрын
It is currently inconvenient, but Unity is trying to popularize ECS as part of their "Performance by default" stance. Everyone can benefit from performance increases. And open possibilities to really help genres like MOBAS, strategy games and simulation games. As soon as Unity ECS tools come out of preview I will recommend all pathfinding in unity to be done utilizing ECS as the performance increase is incredible.
@JohnSmith-ox3gy
@JohnSmith-ox3gy 3 жыл бұрын
ECS is bot inherently more complex, clean code is one of its benefits.It is time consuming and expensive to retrain developers.
@jedhubic
@jedhubic 3 жыл бұрын
OOP is often what people say is normal cause that's what they know. Working in large games there is an underlying benefit to ECS which is the tenets of data oriented design. Even if performance isn't an issue it's good to know about different approaches to managing sets of data at a system level, because normal human OOP can often become very circular and gross, and even under the best conditions from a (usually never senior) programmer who swears they'll only ever write perfect code, there can still get to be an abstract level of bloat to deal with. The very fact we have games running in loops lends some credence as to why ECS and data driven design can be useful. Remember that these are just tools, and the more tools you know and understand, the better you'll be at solving problems. Framing everything in the context of "this or that" is the only way means you're generally choosing to stay ignorant to some degree.
@sabriboughanmi2435
@sabriboughanmi2435 2 жыл бұрын
I'm creating a mobile project in Unity using DOTS (ECS), and performance isn't the only reason I'm doing it, everything is easier to do when the data is ready! (networking, gameplay, Rendering ... )
@nomadshiba
@nomadshiba 2 жыл бұрын
once you understand, learn it, get used to it ecs is cleaner, more understandable easy to use and modify. it's not just good for performance, it's good for the code structure.
Bob Nystrom - Is There More to Game Architecture than ECS?
23:06
Roguelike Celebration
Рет қаралды 189 М.
When Your Game Is Bad But Your Optimisation Is Genius
8:52
Vercidium
Рет қаралды 1,3 МЛН
Китайка и Пчелка 4 серия😂😆
00:19
KITAYKA
Рет қаралды 1,5 МЛН
La final estuvo difícil
00:34
Juan De Dios Pantoja
Рет қаралды 29 МЛН
WHY DOES SHE HAVE A REWARD? #youtubecreatorawards
00:41
Levsob
Рет қаралды 39 МЛН
He tried to save his parking spot, instant karma
00:28
Zach King
Рет қаралды 18 МЛН
Asset Manager Explained | Inside Unreal
1:41:10
Unreal Engine
Рет қаралды 67 М.
The ONLY texture a game NEEDS [UE4, valid for UE5]
18:56
Visual Tech Art
Рет қаралды 68 М.
Giving Personality to Procedural Animations using Math
15:30
t3ssel8r
Рет қаралды 2,4 МЛН
Unity DOTS vs Assembly Benchmark - Which is fastest?
30:34
Lingon Studios
Рет қаралды 79 М.
Mathieu Ropert: Data Storage in Entity Component Systems
1:09:50
SwedenCpp
Рет қаралды 1,9 М.
Entity Component System (ECS) - Definition and Simple Implementation
28:02
Индуктивность и дроссель.
1:00
Hi Dev! – Электроника
Рет қаралды 1,6 МЛН
What model of phone do you have?
0:16
Hassyl Joon
Рет қаралды 73 М.
Apple, как вас уделал Тюменский бренд CaseGuru? Конец удивил #caseguru #кейсгуру #наушники
0:54
CaseGuru / Наушники / Пылесосы / Смарт-часы /
Рет қаралды 4,6 МЛН
Main filter..
0:15
CikoYt
Рет қаралды 551 М.
#miniphone
0:18
Miniphone
Рет қаралды 12 МЛН
Очень странные дела PS 4 Pro
1:00
ТЕХНОБЛОГ ГУБАРЕВ СЕРГЕЙ
Рет қаралды 364 М.
Теперь это его телефон
0:21
Хорошие Новости
Рет қаралды 2 МЛН