Does anyone know a way of either preventing the user deleting a Game Object, or catching the event and clearing up data? I’m writing an editor extension where node objects are connected to each other, and need to be disconnected from each other elegantly before they are destroyed (eg, to allow re-connecting of the node topology). Whilst I can do some of that work in an OnDestroy() block, the OnDestroy (and OnDisable) is called every time you enter the editor’s play mode, which makes it unsuitable. Ideally I need some kind of OnUserDelete() block that I can use in either an editor script, or a standard script with [ExecuteInEditor] enabled.
Has anyone else encountered this problem/got a solution?
I imagine GameObjects, due to their involved nature with Unity, give him the most accessible commands? Just drawing at straws. .hierarchyWindowChanged, didn’t know that, yay.
Nope, it’s a good and valid question: originally they were just data stored in a class and manipulated with handles, but it became very complicated to deal with all the ways they could interact (a single path, fine, but an arbitrary number intersecting in various positions…), and it was impossible to animate them. As GameObjects manipulating them in the scene is easier (I had a lot of problems emulating the default behaviour of transforms, specifically with scaling and multiple selections), as is Undo, and better integration with Unity’s default systems. Now the way I have it set up at the moment is more flexible, if a bit clunky.
Awesome, I’ll give that a go tomorrow! Does it execute before the change? Also, how would you distinguish the change? (Event.current.commandName == “Delete”?)
Those events are fired after a change occurred, and are also fired when you add object, load scene, parent an object to another, etc… Anytime the Hierarchy window is modified.