Search Unity

Memory Layout of EntityArchetypes

Discussion in 'Entity Component System' started by zee_ola05, Jun 13, 2018.

  1. zee_ola05

    zee_ola05

    Joined:
    Feb 2, 2014
    Posts:
    166
    Does this mean that the entities are grouped in memory in contiguous chunks?
    Like this?
    Code (CSharp):
    1.  E1  E2  E3
    2. |A,B|A,B|A,B|    <----- memory
    What if I add another component, C, to E2? How would it look like?
     
    Last edited: Jun 13, 2018
  2. zee_ola05

    zee_ola05

    Joined:
    Feb 2, 2014
    Posts:
    166
    The more I read, the more I think that this is actually how it is laid out in memory, can anybody confirm?

    Code (CSharp):
    1. // For Archetype X
    2. |A1|A2|A3|   // Component A's
    3. |B1|B2|B3|   // Component B's

    But, again, what happens if I add component C to an entity of archetype X, when the component wasn't initially defined as part of the archetype?
     
  3. capyvara

    capyvara

    Joined:
    Mar 11, 2010
    Posts:
    80
    It's the second way, when you add a component C to an Entity a new archetype will be created (it it doesn't exists yet) and the entity will be moved to it.
     
    zee_ola05 likes this.
  4. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    Here's a great post (which should be in the doc imo) https://forum.unity.com/threads/ecs-memory-layout.532028/#post-3513888

    It moves to a new chunk. If you add C to entity number 2 it would become :

    Archetype AB : |A1|A3|_____ |B1|B3|_____
    Archetype ABC : |A2|____ |B2|_____|C2|____
     
    zee_ola05 and Afonso-Lage like this.
  5. zee_ola05

    zee_ola05

    Joined:
    Feb 2, 2014
    Posts:
    166
    Thank you @capyvara , @5argon.

    @5argon I agree. That link is very helpful. Will probably direct more of my questions, if any, to that thread in the future.