Which function runs first in Editor Script?

This is my first try in extending the editor. I want to execute a certain functionality when the component is added on the gameobject. I can’t find out the function that executes on start like void Awake() does in Monobehaviour. Anyone?

Hi @khamosh132! The Editor class has the OnEnable() message (see here), but it is only called when the Editor is enabled (e.g., when the object is selected an its inspector is drawn).

If you need something to happen when the component is added, whether or not the inspector is open or the object is selected, you might consider adding the ExecuteInEditMode attribute to your MonoBehaviour, which will then cause its Awake/OnEnable/etc messages to be invoked even when the game is not playing. That said, these messages will not be sent in this case if the object in question is deactivated in the hierarchy at the time the component is added, etc. so you’ll need to decide what makes the most sense for what you’re trying to do and how you expect components to be added in your case.