Search Unity

Nested Prefabs in entitys

Discussion in 'Entity Component System' started by Shabbalaka, Jan 20, 2020.

  1. Shabbalaka

    Shabbalaka

    Joined:
    Jan 15, 2018
    Posts:
    154
    Hi Guys,

    I am using entitys to spawn 2 Units but a mere 2 units results in about 70 entitys (See Image)


    Any ideas on the best way to spawn say 100 units or is this the only way to get nested prefabs in entitys??

    Maybe I can add a tag to the parent entity and then children entity?

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using Unity.Entities;
    4. using Unity.Collections;
    5.  
    6. public class Units : MonoBehaviour
    7. {
    8.     public EntityManager entityManager;
    9.  
    10.     public int numSpawn;
    11.  
    12.         public void Start()
    13.         {
    14.        
    15.             entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
    16.  
    17.             Entity e = entityManager.CreateEntity();
    18.  
    19.             var instances = new NativeArray<Entity>(numSpawn, Allocator.Temp);
    20.    
    21.             //NativeArray<Entity> Entities = new NativeArray<Entity>(numSpawn, Allocator.Temp);
    22.    
    23.             entityManager.Instantiate(e, instances);
    24.  
    25.         }
    26. }
    27.  
    This is the code I,m using to spawn the 2 units.
     

    Attached Files: