Search Unity

Copy rig from gameobject and add it to an entity?

Discussion in 'Entity Component System' started by FastTurtle222, Mar 23, 2018.

  1. FastTurtle222

    FastTurtle222

    Joined:
    Dec 24, 2017
    Posts:
    28
    Been trying all morning can't really figure out a way to get the rig from a prototype character, was able to get the animator but not the rig.

    Code (csharp):
    1.  
    2.         [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    3.         public static void Initialize()
    4.         {
    5.             entityManager = World.Active.GetOrCreateManager<EntityManager>();
    6.             playerArchetype = entityManager.CreateArchetype(typeof(Position), typeof(Rotation), typeof(TransformMatrix), typeof(Player));
    7.         }
    8.  
    9.  
    10.         [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
    11.         public static void SceneLoaded()
    12.         {
    13.             playerMesh = GetLookFromPrototype("Soldier-Mesh");
    14.             playerAnim = GameObject.Find("Soldier").GetComponent<Animator>();
    15.             StartGame();
    16.  
    17.         }
    18.         public static void StartGame()
    19.         {
    20.             Entity player = entityManager.CreateEntity(playerArchetype);
    21.             entityManager.SetComponentData(player, new Position { Value = new float3(0, 0, 0) });
    22.             entityManager.SetSharedComponentData(player, new Player { anim = playerAnim });
    23.             Player comp = entityManager.GetSharedComponentData<Player>(player);          
    24.             entityManager.AddSharedComponentData(player, playerMesh);
    25.  
    26.         }
    27.  
    28.  
    29.         private static MeshInstanceRenderer GetLookFromPrototype(string protoName)
    30.         {
    31.             var proto = GameObject.Find(protoName);
    32.             var result = proto.GetComponent<MeshInstanceRendererComponent>().Value;
    33.             Object.Destroy(proto);
    34.             return result;
    35.         }
    36.  
     
    laurentlavigne likes this.
  2. FastTurtle222

    FastTurtle222

    Joined:
    Dec 24, 2017
    Posts:
    28
    Hate to bump it but I still haven't figured it out and have tried everything that I can personally think of to get this to work.