Search Unity

Suggestion: Allow merging of archetypes

Discussion in 'Entity Component System' started by gigamech, Apr 6, 2018.

  1. gigamech

    gigamech

    Joined:
    Mar 31, 2015
    Posts:
    23
    Maybe I'm missing something, but it would be great to have a way to compose archetypes by merging existing ones rather than constructing them out of individual types. For example something like this:

    Code (CSharp):
    1.             var shipArch = EntityManager.CreateArchetype(
    2.                 typeof(Position),
    3.                 typeof(Heading),
    4.                 typeof(MeshInstanceRenderer),
    5.                 typeof(TransformMatrix),
    6.                 typeof(Velocity),
    7.                 typeof(Collider),
    8.                 typeof(Rigidbody)
    9.             );
    10.            
    11.             var playerArch = EntityManager.MergeArchetypes(
    12.                 shipArch,
    13.                 EntityManager.CreateArchetype(
    14.                     typeof(Player),
    15.                     typeof(PlayerInput)
    16.                 )
    17.             );
    Archetypes seem to primarily be intended as a way to optimize memory layout rather than a dynamic class system, so the above suggestion may not be the way to implement it, but some way to create "mix-ins" out of sets of component types would be fantastic.