RepaintHierarchyWindow()
Refreshes the Hierarchy window.
Read time 1 minuteLast updated 5 days ago
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor.CoreModule
public static void RepaintHierarchyWindow()
Remarks
Use EditorApplication.RepaintHierarchyWindow to refresh the Hierarchy window when changes to GameObjects, such as names, icons, or tags, are not automatically reflected in the Hierarchy window.
RepaintHierarchyWindowRepaintHierarchyWindowThis API is in the namespace and can only be used in the Unity Editor. Typically, you combine it with EditorApplication.hierarchyChanged or custom events to ensure UI consistency.
UnityEditorAdditional Resources: EditorApplication.HierarchyWindowItemByEntityIdCallback, EditorApplication.hierarchyWindowItemByEntityIdOnGUI.
Examples
using UnityEditor;using UnityEngine;[InitializeOnLoad]public class CustomHierarchyStyling{ static CustomHierarchyStyling() { // Register a callback to draw custom icons in the Hierarchy. EditorApplication.hierarchyWindowItemByEntityIdOnGUI += OnHierarchyGUI; // Repaint the Hierarchy window when the tag changes to reflect icon updates. EditorApplication.hierarchyChanged += () => EditorApplication.RepaintHierarchyWindow(); } static void OnHierarchyGUI(EntityId entityID, Rect selectionRect) { GameObject obj = EditorUtility.EntityIdToObject(entityID) as GameObject; //Add a tag named "Special" to the GameObject to display the custom icon if (obj != null && obj.CompareTag("Special")) { // Draw a custom icon on the left side of the GameObject in the Hierarchy Rect iconRect = new Rect(selectionRect.x - 20, selectionRect.y, 18, 18); GUI.Label(iconRect, EditorGUIUtility.IconContent("d_Favorite")); } }}