Search Unity

Help Wanted Util Archetype Class

Discussion in 'Data Oriented Technology Stack' started by francois85, Jul 25, 2021.

  1. francois85

    francois85

    Joined:
    Aug 11, 2015
    Posts:
    1,634
    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. francois85

    francois85

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

    francois85

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