Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved EntityCommandBufferSystem won't Instantiate Entity Prefab

Discussion in 'Entity Component System' started by StickyMitchel, Jan 13, 2021.

  1. StickyMitchel

    StickyMitchel

    Joined:
    Sep 2, 2019
    Posts:
    19
    I'm trying to spawn an Entity in my SystemBase System using the EntityCommandBufferSystem (BeginSimulation) via:

    Code (CSharp):
    1. protected override void OnUpdate()
    2. {
    3.    var beginSimulationSystem = m_beginSimulationSystem.CreateCommandBuffer();
    4.  
    5.    Entities.ForEach((Entity entity, SpawnRequest request) =>
    6.    {
    7.  
    8.      beginSimulationSystem.Instantiate(request.prefabEntity);
    9.  
    10.    }).Schedule();
    11.  
    12.    m_beginSimulationSystem.AddJobHandleForProducer(Dependency);
    13. }
    However it doesn't appear to instantiate the Entity at all. Using beginSimulationSystem.CreateEntity works fine but it doesn't seem to be able to create an Entity from a EntityPrefab.

    And I using the CommandBufferSystem wrong or is it a bug?
     
  2. jasons-novaleaf

    jasons-novaleaf

    Joined:
    Sep 13, 2012
    Posts:
    181
  3. StickyMitchel

    StickyMitchel

    Joined:
    Sep 2, 2019
    Posts:
    19
    I remember having that issue before on a different entity so I will keep your solution in mind thanks!

    The issue this time was a small mistake on my part. The prefab entity had an component on it which was checked in another system and deleted there. So every time it spawned it also got deleted again. A slight oversight but fixed now!