Search Unity

Destroying GameObjectEntity

Discussion in 'Entity Component System' started by PuxOrb, Apr 5, 2018.

  1. PuxOrb

    PuxOrb

    Joined:
    Jul 18, 2012
    Posts:
    1
    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.
    and
    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

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    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.
    e.g.
    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

    Bhakti_GL1

    Joined:
    Jul 4, 2018
    Posts:
    17
    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