Search Unity

Can I use pure ECS and hybrid ECS simultaneously?

Discussion in 'Entity Component System' started by Kichang-Kim, Jul 5, 2018.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    Hi. I want to know whether pure ECS and hybrid ECS are work on same world.

    I plan to use ECS for my project, but pure ECS has many missing parts (pyhsics, mechanim, etc).

    Here is my questions:

    1. Can I add pure ECS component to hybrid ECS entity ? (entity which is generated by GameObjectEntity)
    2. Can I iterate combination of pure ECS component and hybrid component in ComponentSystem or JobComponentSystem?
    3. When using hybrid ECS, can I iterate via interface?
    4. If I have many ComponentSystem, it impact to performance? (because ComponentSystem looks that iterates all entities, different with JobComponentSystem)

    Thanks.
     
  2. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    1. First hybrid is just an add on (a subset of pure) and it is not strictly a choose "pure or hybrid" choice. Entity generated with GameObjectEntity uses one thing from hybrid lib that pure does not know about : ComponentArray which can house MonoBehaviour class. Pure only knows about ComponentDataArray. So you can see is no such thing as an ECS entity that becomes entirely hybrid . Rather that entity just contains some ComponentArray which you classify it as hybrid and that does not prevent you to add more ComponentDataArray (pure) to it.

    2. Yes you can put both ComponentDataArray<T> and ComponentArray<T> in the same struct injection.

    3. I don't understand so I would like to see what the code looks like to iterate via an interface?

    4. If you do iterate them (use [ ] indexer with ComponentDataArray<T>) then it costs performance (but fast anyways since that's the tight data highlight of ECS) but just injection is an another story. In before OnUpdate ECS lib prepare just the iteration pointer for you and does not mean it already cost O(n) in relation to your amount of data. Also JobComponentSystem is the same because it also can inject so you can throw those data in the job.
     
  3. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    Thanks for detail reply.

    Please ignore question 3, it is my mistake.

    Also It seems that current EntityManager.SetComponentObject() is not public, so there is no method for adding/removing Monobehavior component to entity at runtime. (Only method is that call GameObjectEntity.OnDisable() then GameObjectEntity.OnEnable() ?)
     
  4. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    I think you can add/remove mono behaviour via EntityManager.AddComponent (not EntityManager.AddComponentData) and EntityManager.RemoveComponent at runtime?
     
  5. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    EntityManager.AddComponent() adds only container for Monobehavior based copmonent and its actual data is always null until SetComponentObject() is called. But SetComponentObject() is internal :(