Entity Component System (ECS) - Definition and Simple Implementation

  Рет қаралды 46,578

Dylan Falconer

Dylan Falconer

Күн бұрын

Learn game programming: programvideogames.com (free course using Odin + Raylib!)
X: x.com/falconerd
➤ The Code: gitlab.com/falconerd/ember-ecs

Пікірлер: 134
@ishdx9374
@ishdx9374 3 жыл бұрын
I'm glad you used C as example, because that's exactly the language I'm using
@climatechangedoesntbargain9140
@climatechangedoesntbargain9140 3 жыл бұрын
wish it was Rust
@ishdx9374
@ishdx9374 3 жыл бұрын
@@climatechangedoesntbargain9140 rust has too many features that can obsturct the original concept
@climatechangedoesntbargain9140
@climatechangedoesntbargain9140 3 жыл бұрын
@@ishdx9374 explain that
@ishdx9374
@ishdx9374 3 жыл бұрын
@@climatechangedoesntbargain9140 the point of an ECS is to have a low-level control of your memory, rust while allows that, it's unpractical, because of the friction it imposes (yes I already programmed in rust for around a year)
@climatechangedoesntbargain9140
@climatechangedoesntbargain9140 3 жыл бұрын
@@ishdx9374 explain how it is unpractical in this context
@Salantor
@Salantor 3 жыл бұрын
This really helped me to finally understand what the hell ECS actually is. Thank you, kind sir.
@DylanFalconer
@DylanFalconer 3 жыл бұрын
Glad I could help
@barondominiclexertux6334
@barondominiclexertux6334 3 жыл бұрын
I've shattered up. The clean code that does the job better (100 times) than code of mine (about 10k lines of code I was proud of). Okay, the man of great mind, you beat me. I realized than my programming skills isn't that great as yours.
@DylanFalconer
@DylanFalconer 3 жыл бұрын
Hah, and then you go on to find a memory leak in my code :D I hope you learned something from this video, the system does have limitations which other commenters have pointed out
@beepisinthezipper9503
@beepisinthezipper9503 3 жыл бұрын
I am working on implementing my own basic ECS for the first time and this video is extremely helpful! Thank you!
@DylanFalconer
@DylanFalconer 3 жыл бұрын
I'm glad it helped!
@sonuaryan5287
@sonuaryan5287 7 ай бұрын
Me to bro
@yrds96
@yrds96 2 жыл бұрын
Thanks for this well explained video, this gonna help me a lot to implement ECS in my game that I am writing in c++. You made one of few videos that really implemented ECS and no just a bunch of components with logic implemented in.
@JohnDoe-mr6mq
@JohnDoe-mr6mq 3 жыл бұрын
I like topics discussed on this channel Appreciate what you're doing!
@DylanFalconer
@DylanFalconer 3 жыл бұрын
Glad you enjoy it! More to come!
@osx8227
@osx8227 Жыл бұрын
I found your channel just recently and I love your videos and the knowledge it provides.
@DylanFalconer
@DylanFalconer Жыл бұрын
Thank you!
@LongestYardstick
@LongestYardstick 2 жыл бұрын
Thanks for the rundown!
@leonlysak4927
@leonlysak4927 Жыл бұрын
Damn I wish this was the first video I came across trying to learn this. Thanks for the very clear explanations and walkthrough dude
@DylanFalconer
@DylanFalconer Жыл бұрын
You're welcome 🤗
@VoyivodaFTW1
@VoyivodaFTW1 6 ай бұрын
This has to be in the top 5 KZfaq videos on the subject. You should be a professor or run paid courses because that was the best explanation on the subject.
@DylanFalconer
@DylanFalconer 6 ай бұрын
Why thank you very much, I'm glad you found it useful :)
@bithunter3215
@bithunter3215 Жыл бұрын
Thanks. Very useful information. Even if the concept is not new, its sometimes hard to see through the jungle of buzzwords. Also liked you showing code in C, which makes it very easy to understand.
@ChronoWrinkle
@ChronoWrinkle 2 жыл бұрын
Wow tht is amazingly helpful as i learn unity dots, getting understanding of it under the hood is priceless, thank you!
@DylanFalconer
@DylanFalconer 2 жыл бұрын
Glad it was helpful!
@itsugo_
@itsugo_ 2 жыл бұрын
Thanks for the clear explanation!
@RickoDeSea
@RickoDeSea 2 жыл бұрын
Best video on ECS so far.
@fabiocroldan
@fabiocroldan Ай бұрын
In the case of bird subclasses, interfaces are used in OPP, example creating a CanFly interface
@vapandris
@vapandris 3 жыл бұрын
it would have been intresting to see how you'd add a new type of entity with it's own behaviour. I was thinking about adding a new flag array (or expand alive-array), that stores what is the type of the entity, and use that, but then if you'll have tons of entities, the system part can be overloaded with if statements. Anyway loved the video! :D
@DylanFalconer
@DylanFalconer 3 жыл бұрын
Generally with these types of systems "types" are just a combination of unique component sets. However, as you said, you may want more types of flags without making separate components, like IS_ON_FIRE, IS_FROZEN, etc. In that case you could end up with a bunch of if statements or you could use something like a state machine.
@astroid-ws4py
@astroid-ws4py 3 жыл бұрын
Wow nice video, Found this randomly, Will follow your channel
@anonimowelwiatko9811
@anonimowelwiatko9811 4 ай бұрын
Cherno mentioned something really important. If you create entities that can have multiple components, store them as pointers or even worse, create them inside Entity, you will end up with high memory usage and in case of iterating through components and dealing with elements, it will become a huge mess with bad performance. Idea of having entity just as an ID or keep this connection to component but within systems, iterate over components, not entities itself is much more appealing and performant.
@kavorkagames
@kavorkagames 3 жыл бұрын
Nice straight forward code. Maybe use an enum to help with the remembering part that makes you uneasy.
@DylanFalconer
@DylanFalconer 3 жыл бұрын
Good idea
@Arctecflare
@Arctecflare 3 жыл бұрын
I missed u
@bollebips9491
@bollebips9491 3 жыл бұрын
Nice video. I have a question though. Since you use a bitmask on the entities to store which components they have, that heavily depends on the order in which you register the components. If you suddenly change the order in which you register them, the system fails. Do you have any plans for handling that? I'm asking because I'm working on my own ECS as well, but can't figure out how to solve this problem.
@DylanFalconer
@DylanFalconer 3 жыл бұрын
I'm not actually using an ECS in the game I'm working on, but I see the issue. If one day you decide that component C is not necessary anymore, but you still register A, B, D, then they will be misaligned. You could just continue to register C until you need another kind of component later on. Not the most appealing solution, but should work okay. Is there another reason you may want to change the registration order?
@bollebips9491
@bollebips9491 3 жыл бұрын
@@DylanFalconer Thx for the reply. I understand that, if you know the internals of your own engine well, this is not really a big issue, as you can just take this small inconvenience into account. I was mostly thinking from the perspective of other people using your ECS. I actually found a pretty nice solution online, where you keep track inside your systems, which entities and components are relevant for that system, not the other way around, where the entity keeps track of that. This way, the order of the components or systems is not important anymore :) Again, great video, and thanks for the reply :)
@AntonioIvoDaSilvaGomes
@AntonioIvoDaSilvaGomes 3 ай бұрын
Nice explanation. What font are you using in your terminal?!
@cyanuranus6456
@cyanuranus6456 Жыл бұрын
I Love Default Cubes in Any Kinds of 3D Game Engines
@RockAristote
@RockAristote 2 жыл бұрын
Powerful
@eien7228
@eien7228 2 жыл бұрын
what is that pig generator project called? i rly wanna start making one but i might need some hints
@spacedoctor5620
@spacedoctor5620 Жыл бұрын
How does your ecs_query handle many systems and many (MANY) entities? I really like the approach you've laid out here, it's helped me in developing my own, but this seems to be a possible bottleneck since this must be queried on every call of your system function. I guess since you don't have a concept of a 'system' in your framework (meaning you aren't keeping any internal state for systems), it's hard to get around this problem, though.
@DylanFalconer
@DylanFalconer Жыл бұрын
I haven't thought about this problem in a long time, but my first approach would be to benchmark and if it's actually an issue then look into caching results.
@cyanuranus6456
@cyanuranus6456 Жыл бұрын
I Love Default Cubes in 3D Game Engines
@tastyham
@tastyham Жыл бұрын
" not working on a game " Unity : *ECS*
@phee3D
@phee3D 7 ай бұрын
does using a bit field to filter entities in this implementation mean the number of component types we can create is extremely limited? For example would using a 64 bit int as the bit field mean our application can only have 64 component types? If so then this really isn't going to be enough for many applications, what would you suggest as an alternative to using a bitfield here?
@cipherpunk7409
@cipherpunk7409 5 ай бұрын
No reason you couldn't have multiple bit fields to handle additional component types.
@phee3D
@phee3D 5 ай бұрын
@@cipherpunk7409 i ended up using sparse sets after reading the article "ecs back and forth" by the creator of entt which solves this problem. But yes multiple bitfields could do however I'm not sure how nicely it would scale if you had, say 200 or more components which is not an unrealistic number especially if your game engine itself uses ecs internally as well as for gameplay programming.
@cipherpunk7409
@cipherpunk7409 5 ай бұрын
@@phee3D Nice solution. I've definitely heard of people doing the multiple bit field solution for 200+ components without performance issues. But it definitely depends on what you're making. Glad you found your path forward!
@3rdGen-Media
@3rdGen-Media Жыл бұрын
Crashes on first call to ecs_query if enough entities aren't registered to trigger the realloc bc state.query_result.list was never malloc'd within ecs_init
@anonymoussloth6687
@anonymoussloth6687 Жыл бұрын
What did you use to create the ui at 10:13? Imgui?
@DylanFalconer
@DylanFalconer Жыл бұрын
Similar, github.com/Immediate-Mode-UI/Nuklear
@911WasActuallyBears
@911WasActuallyBears 3 жыл бұрын
17:50 lol
@cyanuranus6456
@cyanuranus6456 Жыл бұрын
I Love 3D Game Engines Entity Component System
@danieleccleston7928
@danieleccleston7928 3 жыл бұрын
Would a game like smash brothers ultimate benifit from an ECS structures?
@DylanFalconer
@DylanFalconer 3 жыл бұрын
ECS is mostly useful for engine makers rather than game-makers. If you know the types of entities you want to have in your game then you can design a straightforward system for your game with that information. If your game design is fluid and/or experimental then you may benefit from ECS's flexibility.
@danieleccleston7928
@danieleccleston7928 3 жыл бұрын
@@DylanFalconer alright thanks
@danieleccleston7928
@danieleccleston7928 3 жыл бұрын
Nice slides, might I ask which software?
@DylanFalconer
@DylanFalconer 3 жыл бұрын
Cheers! For this one I actually just used images and OBS's "image slide show" option.
@danieleccleston7928
@danieleccleston7928 3 жыл бұрын
@@DylanFalconer oh that's cool thanks
@islandcave8738
@islandcave8738 2 жыл бұрын
Are you sure you don't want to make your tiles entities. Seems like you could make the behaviour of your tiles more flexible by being able to swap in and out different components on the fly and have systems that work on those components.
@DylanFalconer
@DylanFalconer 2 жыл бұрын
Indeed you can do that, it really depends what kind of functionality you want for your tiles. If your tiles can perform actions then it's something to consider for sure. For pure aesthetics, probably not. Minecraft has a type of split system where most solid blocks are just Blocks but more complex things like pistons and furnaces are TileEntities.
@sanderbos4243
@sanderbos4243 Жыл бұрын
The downside of mixing tiles with regular entities is that tile position components will be mixed with entity position components. This could be bad if you have a huge number of tiles and you want to for example do collision checking between the entities, because at least in this video's implementation you'd also loop over every tile while just looking for entity position components. A more efficient and complex implementation should totally sidestep this issue. And the other issue with this video's implementation is of course that adding more components makes things slightly slower. Look up enTT on The Cherno's channel for a showcase of such an efficient implementation.
@tandyabimap-hv6fw
@tandyabimap-hv6fw Ай бұрын
The Only Thing I Needed for "Entity-Component-System" is The Description The Thing That You Playing The Game and The NPC That Destroys You Player is Protagonist NPC as Enemy is Antagonist That's The Thing I Wanna Know
@cyanuranus6456
@cyanuranus6456 Жыл бұрын
Together with 3D Game Engines RGB-Colored Arrows 3D XYZ Axis
@joshopelisabeth2248
@joshopelisabeth2248 6 ай бұрын
This is a very clear explanation! Thank you! But you microphone or recording application is disaster! 😅❤
@arikfm
@arikfm Жыл бұрын
The video started off well but it lost me around the 10 min mark.
@DylanFalconer
@DylanFalconer Жыл бұрын
That's a shame, why is that?
@ugurcan969
@ugurcan969 5 ай бұрын
This is a bad example of ECS, go look for a better implementation.
@DylanFalconer
@DylanFalconer 4 ай бұрын
Can you explain why it's bad? I bet you can't
Bob Nystrom - Is There More to Game Architecture than ECS?
23:06
Roguelike Celebration
Рет қаралды 196 М.
Entity Component System | Game Engine series
43:05
The Cherno
Рет қаралды 123 М.
WHAT’S THAT?
00:27
Natan por Aí
Рет қаралды 13 МЛН
Now THIS is entertainment! 🤣
00:59
America's Got Talent
Рет қаралды 39 МЛН
Stay on your way 🛤️✨
00:34
A4
Рет қаралды 8 МЛН
Dynamic Arrays in C
11:46
Dylan Falconer
Рет қаралды 65 М.
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 696 М.
Turns out REST APIs weren't the answer (and that's OK!)
10:38
Dylan Beattie
Рет қаралды 112 М.
Подробный урок по Entity Component System в Unity
15:27
Insane One - Разработка игр
Рет қаралды 42 М.
FLECS - The Fast Lightweight Entity Component System (C/C++)
10:26
Gamefromscratch
Рет қаралды 20 М.
"Clean" Code, Horrible Performance
22:41
Molly Rocket
Рет қаралды 873 М.
WHAT’S THAT?
00:27
Natan por Aí
Рет қаралды 13 МЛН