OnHierarchyChange()
Handler for message that is sent when an object or group of objects in the hierarchy changes.
Read time 1 minuteLast updated 12 days ago
Definition
- Type: Method
- Namespace: UnityEditor
public void OnHierarchyChange()
Remarks
Actions that trigger this message include creating, renaming, reparenting, or destroying objects in the current hierarchy, as well as loading, unloading, renaming, or reordering loaded Scenes. Note that the message is not sent immediately in response to these actions, but rather during the next update of the editor application. Actions taken with objects that have HideFlags.HideInHierarchy set will not cause this message to be sent, but changing Object.hideFlags will. The OnHierarchyChange() is added to the Unity editor. Adding a new GameObject into the Scene, or changing the position of a GameObject in the Inspector will be observed by OnHierarchyChange(). Similarly, changes to the rotation and scale will be seen.
An animation showing how the OnHierarchyChange can be used. Additional Resources: hierarchyChange The following example script created an EditorWindow that monitors the number of objects and updates whenever the hierarchy changes. Copy it into a file called HierarchyMonitorWindow.cs and put it in a folder called Editor.

{code Modules/UIElements/Tests/UIElementsExamples/Assets/EditorWindowCodeExamples/HierarchyMonitorWindow.cs}
Another simple example.
{code Modules/UIElements/Tests/UIElementsExamples/Assets/EditorWindowCodeExamples/OnHierarchyChangeExample.cs}