Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Destroy(this.gameObject)

Discussion in 'Scripting' started by Yeowza, Oct 28, 2019.

  1. Yeowza

    Yeowza

    Joined:
    May 9, 2014
    Posts:
    48
    When destroying objects this way it doesn't actually destroy them until end of frame and even if you check for null they still return true. What's the proper way to check if they are scheduled to be destroyed?

    I've been setting up a separate bool to check for this but I think there should be an official way I can not figure out.
     
  2. NicBischoff

    NicBischoff

    Joined:
    Mar 19, 2014
    Posts:
    204
    Manage them from a different script on a manager.

    If you want extreme control by frame of them being removed, you could set their position off screen and then destroy them there.

    Generally avoid destroy, rather use a pooling solution and reuse the object if you can.