"Remove Component" method call

Hello,

Which method is called upon removing a component via:

65295-ss.png

… in editor?

I am instantiated many components in Reset() right after the script is added, but can’t find which methods is called on “Remove Component” - I attempted OnDestroy OnDisable but none of those are called.

Thanks.

If your component is decorated with ExecuteInEditMode, then both OnDisable() and OnDestroy() are invoked for it (in that order) when you remove it from the context menu, but only if it is an instance in a scene. If it is a prefab in your project view this method is not called because the object is not considered to be enabled in that context.

If I understand your question, you want to use Destroy (nameOfComponent); or something along those lines.

There’s a more detailed answer here: How delete or remove a component of an GameObject? - Questions & Answers - Unity Discussions