Is there a way to detect a Destroyed Object

So, I’ve destroyed a game object.

If I am holding on to a reference to that object, can I detect if its been destroyed?

:smile: What kind of reference, like gui or debug. In your code you could use a guitext or guitexture. Do you mean in the built game? :smile:

I have a variable holding a reference to the object.

and It may have been destroyed somewhere else, so i want to test for that.

if (someGameObject == null) ....

–Eric

You can check if a reference is null. This doesn’t necessarily mean that the object has been destroyed, but at least you can be sure that it doesn’t exist:

if (!myGameObject) doStuff();

Naw, that won’t work. the variable is assigned before the object is deleted.

So, it has a stale pointer.

The other approach would be to detect the actual destruction of the object, like an “OnDestroy” call. But I didn’t see an event like that.

Either wait a frame or use DestroyImmediate().

–Eric