Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Is ECS useful for everything?

Discussion in 'Data Oriented Technology Stack' started by Arsonist1, Dec 7, 2018.

  1. Arsonist1


    Dec 18, 2016
    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).

  2. Arowx


    Nov 12, 2009
    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


    Dec 18, 2013
    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:

    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


    Digital Ape Moderator

    Apr 11, 2010
    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


    Nov 24, 2010
    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


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