Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  5. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Is ECS useful for everything?

Discussion in 'Entity Component System and C# Job system' started by Arsonist1, Dec 7, 2018 at 1:39 PM.

  1. Arsonist1

    Arsonist1

    Joined:
    Dec 18, 2016
    Posts:
    3
    The way everyone is describing it is as if ECS does everything monobehaviours do, but much faster. My question is should I just be learning to program everything in ECS now? Is ECS more performant even if there's only one element effected (like player movement won't have more than one entity).

    Thanks!
     
  2. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    6,625
    The thing is ECS coverage is still in the works, so you need a hybrid approach to have all of the Unity features in an ECS project.

    If only Unity would produce a simple guide like this (fake) one...


    Also ECS may not be ideal for all programming algorithms/data as it relies on data that fits easily into the L1 cache.
     
    Kirsche and siggigg like this.
  3. Vacummus

    Vacummus

    Joined:
    Dec 18, 2013
    Posts:
    49
    You don't have to do everything in ECS. But I do believe there is a lot of value in writing most of you game in ECS. Beyond having your game perform better by default, ECS also makes it easier to optimize your game when you do run into performance issue. The traditional monobehaviors route (object oriented programming) does not give you many options to optimize. More often than not it will require huge refactors to optimize well and even then it doesn't come close to what you can do with ECS (and Data Oriented Design in general).

    ECS is all about writing code in a predictable and transparent way. What this means is that it will make your code easier to reason about and maintain. Object oriented programming can be very unpredictable making it hard to find bugs. Furthermore, ECS will help reduce complexity and make your game easier to scale, thus not only improving the performance of your game but also improving how fast you can make your game. The reason for this is because ECS combines functional programming values and database design. Here is an article that explains why functional programming and database design help reduce complexity when programming: https://github.com/papers-we-love/papers-we-love/blob/master/design/out-of-the-tar-pit.pdf

    The thing is when you implement the movement of a player entity in ECS, that code will work for any entity that needs movement. So if in your game the only thing that is moving is the player entity, then you won't see much performance gains over the traditional monobehaviors. But if you have more things that will be moving around (which is usually the case) then yes you will see performance improvements. That's one of the big concept of Data Oriented Design: "where there is one, there are many".
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    23,793
    Unity Tiny is the latest example where ECS is useful for everything. It scales from the smallest possible (single) threaded environment right up to I dunno, as many cores as you can shake a stick at. 128? 256? :)

    It's so efficient just talking about data and how to transform it that it doesn't matter what ECS is applied to. It's really useful for everything and the replacement for OOP.

    Most of the world will probably move to ECS for performance critical applications (most big shots do something similar, but still cling to legacy oop and that's changing mostly because when something as big and classically slow as Unity starts doing hand coded C++ perf, you notice).

    Thanks to the team involved :)
     
  5. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    2,950
    ECS is technically useful for everything, and once Tiny isn't restricted to WebGL it will be usable for everything.

    However, there are things you don't care about it for. One-time setup, rarely used functions, pre-game menus rarely need maximum performance. It's handy, though, as on mobile platforms you're eating up less battery time with highly optimised solutions like this.

    When they evolve the editor tools enough there shouldn't be much difference between the Monobehaviour and the Entity ways in actual use, hopefully, and that's when you might as well go full ECS. Both use composition, but ECS is more atomic, therefore a bit more of a chore currently. Use it when you can't squeeze out enough performance from a Monobehaviour-heavy project.
     
  6. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    785
    ECS is a good threaded calculator. If you need fast calculations based on structured data then it is good.