Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to execute chunk iteration for MonoBehaviour components?

Discussion in 'Entity Component System' started by davenirline, Mar 14, 2019.

  1. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    I realized I have some hybrid systems and I wanted to get rid of ComponentArray. However, I can't find an appropriate ArchetypeChunk*Type that can be used for MonoBehaviour components. I ended up using ComponentGroup.GetComponentArray().
     
  2. jeremies_unity

    jeremies_unity

    Joined:
    Oct 16, 2018
    Posts:
    26
    Use
    Code (CSharp):
    1. GetArchetypeChunkComponentType
    to get the type, then use
    Code (CSharp):
    1. GetComponentObjects
    from the chunk. Example for Rigidbody:

    Code (CSharp):
    1. ArchetypeChunkComponentType<Rigidbody> rigidbodyRO = GetArchetypeChunkComponentType<Rigidbody>(true);
    2.  
    3. foreach (ArchetypeChunk chunk in chunks)
    4. {
    5.     ArchetypeChunkComponentObjects<Rigidbody> rigidbodyArray = chunk.GetComponentObjects(rigidbodyRO, EntityManager);
    6. }
    You can then index the array as normal.