Search Unity

Question Util Archetype Class

Discussion in 'Entity Component System' started by RoughSpaghetti3211, Jul 25, 2021.

  1. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,708
    Hello, wondering if someone could help me out with a question. I have a Util class for creating entity archetypes from enum. This util class is used in a public class DataAuthoring : MonoBehaviour, IConvertGameObjectToEntity conversion method to generate an EntityArchetype and to then add to an additional entity. Is there a way to get to the destWorld to CreateArchetype without passing dstManager?

    I assume this will not work.

    var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager; // Wrong World !!!

    Code (CSharp):
    1.  
    2. public static EntityArchetype ToEntityArchetype(MyType type)
    3. {
    4.     var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager; // Wrong World !!!
    5.          
    6.     return type switch
    7.     {
    8.         MyType.A => entityManager.CreateArchetype(typeof(AComponent)),
    9.         MyType.B => entityManager.CreateArchetype(typeof(BComponent)),
    10.         MyType.C => entityManager.CreateArchetype(typeof(CComponent),typeof(AComponent)),
    11.         _=> throw new ArgumentException(nameof(MyType.type), $"Not expected value {type}")
    12.     };
    13. }
    14.  
    thanks in advance
     
  2. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,708
    actually, this whole thing doesn't seem to work at all, how would I do this?
     
  3. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,708
    Maybe it's best to just return a components[] ?