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

What ever happened to the discussion over sub-entities?

Discussion in 'Entity Component System' started by Abbrew, Feb 20, 2021.

  1. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    I can't find the original thread, but here's the gist of it: Since an entity archetype with too many components would decrease the amount of entities per chunk, a proposed solution was to decompose an entity's many components into multiple entities each owning a subset of the original's components. The original entity would instead own small components with a single field referencing each sub-entity that stores the real components. Should one of these sub-entities become too large the same pattern is applied again, resulting in a tree-like structure. where each layer of siblings remains at small sizes.

    I can see some pros with this approach. Each entity is downsized so that many entities can be iterated over per chunk. Also, this adds organizational benefits design and performance-wise, since each sub-entity's components should cover a single field of responsibility, and can be solely iterated over without resorting to random access via XFromEntity.

    There are cons though. Maintaining this tree structure requires constant refactoring in the case that an entity needs to be broken up into sub-entities. Also, the dependencies between sub-entities (basically, relationships between responsibilities like "communication" entities and "suppressing fire" entities for a hypothetical WWII-style game) cannot be eliminated completely, so if they exist then their mutual parent must be iterated through, and their own sub-entities fetched via XFromEntity.

    Are there any other pros and cons? Is this a valid practice if archetype sizes are bloating out of control?
     
  2. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    I figured a diagram would better illustrate sub entities, so here it is
     
  3. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Unless I'm misunderstanding, wouldn't it be easier to just increase the chunk size?
     
  4. UsmanMemon

    UsmanMemon

    Joined:
    Jan 24, 2020
    Posts:
    87
    @Abbrew this will create many indirect lookups. Just custom chunk sizes for some archetypes would be enough.
     
    Abbrew likes this.
  5. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    677