OnDestroy called when object lost focus in editor

Hi,

I don’t understand how OnDestroy() and OnDisable() are supposed to work in custom editor scripts.

On the scene I have gameobject with script Manager attached. Besides I have custom editor script ManagerEditor :

[CustomEditor(typeof(Manager))]
[InitializeOnLoad]
public class ManagerEditor : Editor 
{
	public void OnDisable()
    {
        Debug.Log("Disable Editor");
    }

    public void OnDestroy()
    {
        Debug.Log("Destroy Editor");
    }
}

Why, every time, I unselect this object (gameobject with Manager attached) in hierarchy window, I see both Debug.Log messages (Disable Editor and Destroy Editor) ?

OnDestroy and OnDisable means losing focus ?

Thank you for clarifying this.

When you deselect a object the editor is no longer used, is normal destroy the editor to release resource and make a new when you select the object again.

The solution is: place OnDestroy() in MonoBehavior script (instead of Editor script) and add ExecuteInEditor attribute for this MonoBehavior.