Detect GameObject destruction while in EditorMode

Hi everyone!
I’m currently developing basic waypoint navigation in unity. I want to use editor to manage waypoints connections, positions, etc…

I create Waypoint in this way:

[CustomEditor( typeof(Waypoint) )]
public class WaypointEditor : Editor
{
    [MenuItem("GameObject/Create Waypoint")]
    public static void CreateWaypoint()
    {
        GameObject obj = new GameObject();
        obj.AddComponent("Waypoint");
        obj.name = "Waypoint " + (PatchFinder.getID());

        // set position...        
    }
}

I want to be able to delete waypoints using EditorView tools (rightclick->delete or “del” key) or by Inspector button. I have to override some delete/destroy method to clear waypoints connections and remove waypoint from PathFinder list. I’ve tried OnDestroy() but it works only in GamePlay mode.

Thanks

You might wanna try “OnDestroy” in your WaypointEditor class. It does get called, when you object/component is destroyed in edit mode. Just be sure to check what exactly was destroyed, as it gets called for all editors on an object, if any component was destroyed.

EDIT: Okay, sorry, I actually can’t get it to work myself. The OnDestroy call is before anything is being destroyed, and since it’s called on every editor, I find it impossible to tell, what is is actually going to be destroyed.