- Home /
Question by
Skjalg · May 01, 2011 at 06:48 PM ·
editor-scriptingcomponenteditorwindow
How can I listen for remove and add component events
When using the inspector to remove or add a component, how can I listen for these events in my EditorWindow script?
Comment
Best Answer
Answer by hellcats · May 02, 2011 at 02:07 AM
There aren't such detailed event handlers in Unity, but there is sort of a "master" event you can use: EditorApplication.update. This is like MonoBehavior.Update(), but for the editor itself. You could use this to serialize the currently selected object (using SerializedObject) and then look for changes to it each time update fires. Add the InitializeOnLoad attribute to your class and it can self-install in the class constructor like this:
[InitializeOnLoad] public class Tracker { static Tracker() { EditorApplication.update += Update; }
static void Update() {
// Play with Selection here
}
}