- Home /
How to get notification of moving a GameObject in the hierachy when editing the scene?
Hello, im making an asset and using editorscripting where i need to get a notification when the developer have moved a gameObject in the hiearchy.
A very simple example could be
Here, i have two GameObjects with a "Book" component, and those Books have a GameObject array that have "Page" components. They both need reference to eachother.
So if i for example want to move the ManualPage GameObject to BookTwo as a child, then i need to set the new references so the Page have the correct reference to its Book (parent) and the Book have to add the ManualPage to the Pages array so it knows it contains the ManualPage
So how can i get the notification when moving a gameobject? I have tried "OnInspectorGUI()" which will be called if i move a gameobject with a Page component, then i can always set/check if it has moved, but if the page is a child of an empty gameobject, and i move the empty gameobject to another Book, then the "OnInspectorGUI" wont be fired, so then the Page will not get notified.
Hope someone has a solution. Thanks in advance.
Answer by chechoggomez · Oct 01, 2014 at 06:22 PM
You could try to use OnHierarchyChange()
http://docs.unity3d.com/ScriptReference/EditorWindow.OnHierarchyChange.html
But this is when you are using an EditorWindow.
Your answer
Follow this Question
Related Questions
The parallel function to Selection.activeObject in the Inspector? 0 Answers
Any way to invisibly tag an object? 1 Answer
Running a script when Unity starts. 3 Answers
How can i get the center of the entire editor window 0 Answers
Fill/populate [SerializeField] automatically via script in editor mode? 3 Answers