Is it possible to detect if an Object is *being* destroyed?

It is easy to check if a UnityEngine.Object has been destroyed by checking it for null. But, because Destroy is by default not immediate (and the documentation recommends against using immediate for some reason) there is a brief window until the next frame where an object is on death row but obj == null returns true.

Is it possible to check whether Destroy has been called on an object but it is not yet destroyed?

The Unity method OnDestroy will get called when the object has had Destroy called on it.

void OnDestroy()
   // Do whatever

I’m not aware of anything built into unity that would work like


However, it is possible to mark the gameObject as about to be destroyed yourself. For instance rename the gameObject or change the tag, i.e."ToDestroy";

then you can check however you have decided to mark your gameobject