New way of CODING in Unity! ECS Tutorial
Video Statistics and Information
Channel: Brackeys
Views: 537,829
Rating: undefined out of 5
Keywords: brackeys, unity, unity3d, beginner, easy, how, to, howto, learn, course, tutorial, tutorials, fix, tip, game, development, develop, games, programming, coding, basic, basics, C#, ECS, entity, entities, entity component, entity component systemmcomponent, system, systems, approach, new, performance, change, example
Id: _U9wRgQyy6s
Channel Id: undefined
Length: 9min 10sec (550 seconds)
Published: Sun Jun 03 2018
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.
I feel these comments lack a discussion about how ECS enforces a certain structure to your code.
A trivial project gets no benefit out of ECS. But when you are dealing with large systems in your game that all interact between their own interfaces, ECS enforces the structure of that interface.
When you're only using monobehaviours there's a lot of decision to be made about where the logic of your game lives. Should the player have a reference to the UI to update the healthbar? Or should the UI have a reference to the player? This might be an easy decision when your game only has 5 scripts in it. What about when another developer starts working on their own enemy and enemy health bar? What if they answer these questions differently than you? Before you know it your project has 200+ scripts and the interfaces between how they all interact are inconsistent and a nightmare to maintain, refactor and debug.
Even the best developer will make the wrong decision sometimes. If you're working on a big project, whether by yourself or on a team, ECS gives you a much more structured set of decisions to make:
Now I can design myself a UIHealthBarSystem that relies on a HealthComponent. Anything with health can have a HealthComponent. My UI doesn't even know that a player exists which is great because it doesn't have to. It only needs to know that there's some entity that has a HealthComponent to it. Now, any health bar I show on my UI uses the same interface and I don't have to ask any questions like when I was using only MonoBehaviours.
ECS absolutely has a learning curve and it adds a layer of overhead to prototyping. IMO the benefits do outweigh the negatives though, and I don't plan to start a new large project without using ECS in some capacity.
This makes so much more sense. Component based systems are confusing because data and logic are combined, this is much better.
This is perfect for massive games honestly
I wish he explained how it actually is more efficient than monobehavior. I'm not convinced it is worth the effort without any evidence of better performance or easier scalability.
EDIT: My understanding from the replies is that, basically, there is a greater overhead calling the Update() method for a hundreds of objects with the regular monobehavior practice, versus just using a loop to go through those objects and update them all in one main update method.
The biggest reason to use ECS is that it optimizes really easily with data locality. RAM < L2 cache < L1 cache is the reason modern devs like C# over C++ (because the garbage collector does some of these optimizations for you).
Structure-wise, thereβs not really a huge reason to use it over other patterns. Quick optimization is 99% of the reason we do this.
ECS is looking pretty good. I'm sure we've all done this "move similar code into a singleton" type pattern before and have seen it work.
Honestly, anything that helps the overhead of the Unity lifecycle is a welcome change but I can see how the Entity Manager has optimization opportunities. The EM should have an easier time keeping track of entities in a scene than every behavior trying to find and manage all the components on its respective GameObjects.
I'm not sure how code will look in a pure ECS world though. How does UI work?
Even from my very fresh perspective in development, Iβve kept finding the monobehavior system just not feeling natural. This actually makes much more sense, and Iβm looking forward to using this. Iβm ready to go pure ecs right now, regardless if I benefit from the performance efficiencies.
Very excited about this. It's still on the very early stage of implementation so essentially it's still not pragmatic. It makes so much more sense writing codes this way imo.
I was often bugged out by the hundreds of monobehaviour updates running. I was always using a similar approach that uses monobehaviour only to store data and feed/register them into a main system that run loops as an alternative. Not much of a perfect solution but it works.
Seeing them to add them into unity natively makes me nothing other than a happy man.
I'd definitely prefer this approach to slapping MonoBehaviors on GameObjects. I've written a few ECS solutions for Unity and I was always happier with them than what you normally do. So, yes, it's great. But right now, it's simply not finished, lacking a lot of features.
You can use the hybrid mode for now, having Monos on GOs, and write systems that operate on groups of Monos, but that's just half-way to the goal.
I'll rather wait until they have a more fleshed-out version and then give it a serious go.