- Home /
Checking if a component has been removed or not at runtime
Is there a way to check if a component has been removed at runtime?
Comment
Answer by Statement · Dec 26, 2010 at 10:31 PM
I guess you can see if any reference to the component is null, or handle this during OnDisable. Though, this doesn't mean the object is removed, only that is has been disabled. Any removed objects does disable before they are removed.
if (otherComponent == null)
{
// It's been destroyed...
}
- Note: For C#/.NET programers it might seem strange that a reference can become null without prior alert, but this is how unity works. Any reference to any script can become null as soon as the object is destroyed.