Search Unity

How Do Entities Index To Relevant Component Datas?

Discussion in 'Entity Component System' started by TheGabelle, Apr 11, 2019.

  1. TheGabelle

    TheGabelle

    Joined:
    Aug 23, 2013
    Posts:
    242
    I'm familiar with databases so the ECS memory layout concept isn't new. What is strange is how an entity (an id plus version number) automagically computes indexes into respective data arrays. How is this done?
     
  2. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    It's done via a lookup.
    There's a single freelist of EntityData structs, each containing a reference to the chunk and index offset for that Entity.
    The Entity.Index refers directly to the index in the freelist, from which it can then directly index into the chunk and individual components. Double indirection lookup.
    However for the most part, you're simply iterating arrays where no lookup is required.
    Only the index is needed for the lookup. The version serves another purpose.
     
    TheGabelle likes this.