Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Destroy(this.gameObject)

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

  1. Yeowza

    Yeowza

    Joined:
    May 9, 2014
    Posts:
    24
    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:
    145
    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.