Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How do I Destroy an Entity in JobComponentSystem?

Discussion in 'Data Oriented Technology Stack' started by Reborn1214, Mar 15, 2019.

  1. Reborn1214

    Reborn1214

    Joined:
    Jan 19, 2019
    Posts:
    15
    When I destroy an Entity, an error message "System.ArgumentException: The entity does not exist .." appears.
    I used "EndSimulationEntityCommandBufferSystem" and "EntityCommandBuffer.Concurrent" to destroy this Entity.I konw,this Entity is used in some of my systems, but, Isn't "EndSimulationEntityCommandBufferSystem" the last system to run?
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    7,394
    Check, if you don't run system more than once, trying to destroy same entity.
    First time your entity may be destroyed, but at second run, may not exists.
    Depends, how you structured the system.
    But ECB should be able work with destroy in jobs
     
  3. Reborn1214

    Reborn1214

    Joined:
    Jan 19, 2019
    Posts:
    15
    Thank you for your answer.I think maybe it's not that I destroy Entity twice time.Because, I added a ComponentTag to this Entity.( like this, commandBuff.AddComponent(entity,new LifeTime{value = 1f}) ) and I added a attributes to my job.(is [ExcludeComponent(typeof(LifeTime))] ).

    I have 3 System. like "ASystem" ,"BSystem" and "MiddleSystem". There is one ArrayNative in MiddleSystem.
    Both Systems A and B access this ArrayNative, In A, i destroy some Entity in this ArrayNative, but Now ,i konw maybe
    these entity I want to delete are being used by B.What should I do to avoid errors?
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    7,394
    Did you applied UpdateAfter, or UpadateBefore keys in systems?

    Is good to ensure, that destroying system is last in a frame.
     
  5. Reborn1214

    Reborn1214

    Joined:
    Jan 19, 2019
    Posts:
    15
    I specified [LaterSimulationSystemGroup] for my DestorySystem and [SimulationSystemGroup] is specified for other systems.I don't know if that's the reason for "Allocator.Persistent" ,"IJobParallelFor" or "ComponentDataFromEntity".
     
    nicolasgramlich likes this.
  6. nicolasgramlich

    nicolasgramlich

    Joined:
    Sep 21, 2017
    Posts:
    182
unityunity