Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Destroying GameObjectEntity

Discussion in 'Data Oriented Technology Stack' 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