Is there a reason why Destroy wouldn’t work on a GameObject instance, but DestroyImmediate would?
I don’t have any references to the objects. My system is basically this. I call DestroyItems() from OnGUI. DestroyItems looks for gameobjects with a specific tag. I then go through and destroy the objects in the array. The problem is if I use GameObject.Destroy they won’t get destroyed. They WILL if I hit the button again or if I use DestroyImmediate.
I’ve tried recreating the system in a simple scene, but it works just fine. So now I really don’t know what’s going on.
It works just fine. If you’re checking to see if they’re gone in the same frame you call it, though, they’ll still exist. Destroy removes the objects on the frame after it’s called.
I’d have to see the code involved, to be honest. In my experience, though, Destroy() has never failed to destroy something that was properly referenced.
Do you keep any static references to any MonoBehaviours around? e.g. “MainGame.instance = this;” in Start(), for convenient reference from other behaviours? I’ve run into a deallocation problem due to this before.