Destroy doesn't work DestroyImmediate does

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.

So… any reason why Destroy wouldn’t work?

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.

Not in this case. They remain in the world(as I continue to play the game). That’s why I’m wondering what would prevent Destroy from working.

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.

yeah, that’s why it’s strange. I’ve never had it do this before. I’m going keep trying to recreate the bug in a simple scene.

I was just wondering if there is some special case that would cause this behavior. Devs?

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.