Is there something like a OnRemovedComponent method?

I got a script file spotlight.cs.
When the script is added to a gameObject, it creates a child object and attaches a spotlight to it.

But when the script component gets removed in the editor, it should also delete the child gameObject it created. But how? OnDestroy doesnt seems to trigger in the editor. It’s possible to delete it manually but it’s not really user friendly.

Thanks for help :slight_smile:

Unfortunately there’s no such callback (at least as far as I know) - You could mark your script with [ExecuteInEditMode] that way OnDestroy gets called in-editor. Or write a custom destroy method in your script or better have an IDestructable interface but both of these work at runtime, or as a last resort write a custom editor window if you don’t like to use ExecuteInEditMode and have the destroy keys as MenuItems so you could quickly delete objects.