Search Unity

IComponentData and Job System on Hybrid ECS

Discussion in 'Entity Component System' started by Bhakti_GL1, Nov 29, 2018.

  1. Bhakti_GL1

    Bhakti_GL1

    Joined:
    Jul 4, 2018
    Posts:
    17
    For the first time when I know about ECS (Pure and Hybrid), I think it will be a good approach for game development future, especially in Unity. Changing 180 degrees of our way of thinking from OOP to DOD is really painful but worth. The way we treat "Player", "enemies", etc no longer as Gameobject, instead we treat each of them as an Entity that stores data. It will be "Fun", they said.

    I just want to know about some of these topics below :
    1. Do you guys use Unity Physics like Rigidbody and Collider for Pure ECS, don't you?

      *I ended change to Hybrid ECS by creating one Child Gameobject for each Entity and adding Collider and Rigidbody on it. I create some lists (like Player, Animation, Position, Enemy) to determine how the child and it's parent communicates. For example, Child Gameobject will equalize its transform position using position value from List Position by their index (parent and child indexes are initialized when they are instantiated, the Entity write its Position value to list to be read by its child). But then I'm stuck for collision physics. :(

    2. How do you guys use Job on Hybrid ECS? (I tried this when I change my Pure into Hybrid ECS for the sake of Unity Physics. and yes I know it's pointless)

      *Somehow some Value on IComponentData that attached to Unity Gameobject NOT "Modified" by Job system on the Inspector. I checked on Entity Debugger and Boom! it's modified. I don't know how why there is like two different components when an Entity Component implemented on Unity Gameobject.
    I would be grateful if you explain this in "super detail" mode (seriously, I'm not that smart, I just won't give up for bloody Unity ECS struggle :) )
    I'm sorry for my rip English, Thank you very much !!! and yes I currently prototyping :)
     
  2. SubPixelPerfect

    SubPixelPerfect

    Joined:
    Oct 14, 2015
    Posts:
    224
    1) you need to watch ALL ECS-related unite talks (some of them worse to be watched a few times)
    2) read all documentation for ecs and jobs
    3) understand how all samples work
    4) read 300 topics on this forum
    5) look at ecs source code

    and I ensure you you'll start to understand much more about DOD and fall in love with it

    you simply can't switch from OOP to DOD without learning a lot of new stuff
     
    Bhakti_GL1 likes this.
  3. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    GameObjectEntity provides 2-way sync as follows

    - OnBeforeSerialize : When you look at the inspector (highlighted that GO) this method is repeatedly called. At this moment a data sync back from ECS to your wrapper and you will see the value change accordingly. If you have a job system modifying its ECS Entity counterpart you will see a value live-changing. I am not sure why you don't see the change. Are you sure that value is serializable? Is the entity you changed at ECS side still the same entity as you can get by .Entity on the GOE?
    - OnValidate : This happens when you play with values in an inspector. It will try to set ECS side to the same data if it is still there. This includes when you use programmatic change on .Value of your wrapper it will sync to ECS immediately. (in which your wrapper will contact GOE for the correct entity)
     
    Bhakti_GL1 likes this.
  4. Bhakti_GL1

    Bhakti_GL1

    Joined:
    Jul 4, 2018
    Posts:
    17
    This is the answer that I fear the most :(

    but I got the point, thx a lot !
     
  5. Bhakti_GL1

    Bhakti_GL1

    Joined:
    Jul 4, 2018
    Posts:
    17
    I'm sure that the entity is the same entity on the GOE, I have no idea why my entity component on the entity debugger and inspector are not sync.

    I'll check and try to modify my code to fix this,
    Thx for your answer :)))