Search Unity

How "Pure" does Pure ECS have to be?

Discussion in 'Entity Component System' started by battletomasetti, Aug 14, 2018.

  1. battletomasetti

    battletomasetti

    Joined:
    Aug 14, 2018
    Posts:
    2
    So I have been trying to engulf as much information about ECS as possible the past few weeks as I am in the early stages of my first game.

    One thing that has bothered me is how the wording of all these posts and guides sorta make it seem that its either PURE ECS or no ECS.

    Is that the case? Because I really think my game will benefit from a Pure ECS system since it has a very large number of simulated units on screen at once. buuut, at the same time, it sounds like shooting myself in the foot when it comes to using ECS for my UI elements.

    Is it ok to have a little bit of mix? Or does my entire game need to be 100% pure ECS code?
    I guess expanding on the question if using a mix is ok, what about mixing Hybrid and Pure ECS? That would make my initializing of my unit prefabs with varibles a little easier to wrap my head around.
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    The definition of pure is that your entities have no GameObjects. Everything else is hybrid. For a lot of cases, pure isn't really that feasible at the moment unless you want to do a lot more work.

    Now hybrid is a much more broad term and the degree you utilize ECS and Jobs is up to you.

    You can have a hybrid system that only uses ComponentSystems and no jobs, very little performance gain but nicely organized code. Or you can go to the other extreme where all your data is IComponentData, work is done in Jobs and the only time you use GameObjects is to use existing systems (physics etc) - my personal suggestion.

    There is no reason you can't write some of your systems as a complete pure solution while other systems that depend on physics, or animations etc use a slightly hybrid approach.
     
    battletomasetti likes this.
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    In current state, you have classic OOP way of programming with GameObjects, ECS which is new way and Job Systems. Job System can work with OOP without ECS. However, it benefits a lot when Job System and ECS comes into play together.

    Now, you can have Hybrid ECS and Pure ECS programming patterns.
    From my understanding:

    - Hybrid ECS allows to utilize Pure ECS features, while manipulating physically with OOP Game Objects. However, you may loose on performance gain benefits from Pure ECS, when using hybrid. The rendering also happens on "OOP side". You can manipulate Game Objects in real time.

    - With Pure ECS, you avoid manipulating, or accessing OOP Game Objects, other than at scene initialization, to grab relevant meshes and materials. Then you process data and if relevant, position of meshes, using ECS. Rendering happens on "ECS side". You can not drag atm ECS rendered meshes. Unless you explicitly program user inputs, to do so.

    And then, nothing stops from mixing both. Yet need to be aware and careful, where are benefits, and where Pure ECS gain may be lost. It depends what data you are processing.

    For example, you can have completely rendering and collision detection, using current OOP physics engine, while using using Pure ECS, to process AI data.
     
    battletomasetti likes this.
  4. battletomasetti

    battletomasetti

    Joined:
    Aug 14, 2018
    Posts:
    2
    Thank you guys so much! Man that takes a load off the shoulders. Ive been spinning wheels for 2 days now trying to wrap my head around coding some parts in ECS. When the main part I want it for is handling the massive small changes from all the units on field. I can actually follow some of the ECS Hybrid guides then too.

    Appreciate it!