Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Destroying GameObjectEntity

Discussion in 'Entity Component System and C# Job system' started by PuxOrb, Apr 5, 2018.

  1. PuxOrb


    Jul 18, 2012
    I have a scene that I setup with pretty heavy reliance on GameObjectEntity and ComponentDataWrapper (as in every IComponentData has a corresponding ComponentDataWrapper so I can assemble everything in prefabs).
    I'm trying to destroy these GameObjects now. I can cleanly destroy the Entity in a job with PostUpdateCommands.DestroyEntity, but that doesn't destroy the GameObject it's associated with. If I destroy the game object, the OnDisable function seems to clean up the Entity immediately giving me
    ArgumentException: All entities passed to EntityManager must exist. One of the entities has already been destroyed or was never created.
    Internal: JobTempAlloc has allocations that are more than 4 frames old - this is not allowed and likely a leak

    Is this a bug in the system, or would the accepted solution be to destroy the Entity on the EntityCommandBuffer and trigger another component to wait for the end of the frame and cleanup the GameObject then?
  2. M_R


    Apr 15, 2015
    it seems that GameObjectEntity destroys its entity during OnDisable.
    you can mark those entities for destruction (i.e. add a DestroyEntity component data) then have a system that actually destroys the game objects on the main thread.
    Code (csharp):
    1. OnUpdate {
    2.     foreach entity with (Transform, DestroyEntity) Destroy(entity.transform.gameObject);
    3.     foreach entity with (DestroyEntity, SubtractiveComponent<Transform>) entityManager.Destroy(entity)
    4. }
  3. Bhakti_GL1


    Jul 4, 2018
    Try to destroy your entity GO with some amount of times :
    GameObjectEntity.Destroy([B]YoursEntityGO[/B], 0.01f);

    I got to destroy an entity gameobject with a "specific" time when I encounter ArgumentException : The Entity Does Not Exist. I don't know how it works, I know it's stupid, but it's works :D