Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  5. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Destroying GameObjectEntity

Discussion in 'Entity Component System and C# Job 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:
    286
    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:
    5
    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