BUG? - g.gameObject.hideFlags = HideFlags.HideInHierarchy does nut update hierarchy

g.gameObject.hideFlags = HideFlags.HideInHierarchy; does not update the hierarchy.
Didn’t found any command to redraw the Hierarchy. Only recompiling a script updates the Hierarchy. I’m doing here anything wrong?

Unhide works well.

using UnityEditor;
using UnityEngine;

public class UnHideInvisibleGameObjects : MonoBehaviour {
    [MenuItem("Tools/Unhide All GameObject In Hierarchy")]
    static void UnhideGameObjectsInHierarchy() {
        foreach (var t in GameObject.FindObjectsOfType<Transform>()) {
            if (t.gameObject.hideFlags != HideFlags.None) {
                t.gameObject.hideFlags = HideFlags.None;
                Debug.Log("Unhide Gameobject : " + t.gameObject.name + "");
            }
        }
    }
    [MenuItem("Tools/")]

    [MenuItem("Tools/Hide Selected Gameobject In Hierarchy")]
    static void HideSelectedGameObjectsInHierarchy() {
        var gs = Selection.gameObjects;
        foreach (var g in gs) {
            if (g.gameObject.hideFlags == HideFlags.None) {
                g.gameObject.hideFlags = HideFlags.HideInHierarchy;
            
                //var ac = g.gameObject.activeSelf;
                //g.gameObject.SetActive(true);
                //g.gameObject.SetActive(ac);

                Debug.Log("Hide Gameobject : " + g.gameObject.name + "");
            }
        }
    }
}

I know of this method, that redraws just every view, perhaps as a workaround:

UnityEditorInternal.InternalEditorUtility.RepaintAllViews();

Thanks, tried it but does not work for any reason.
Seems the internal hierarchy display array does not receive the changes are made on a gameobject.

Did this work in previous versions?

Does not work in 2019.1.8f1 also.

How about EditorApplication.RepaintHierarchyWindow(); ?

Thanks, but nope!

also
UnityEditorInternal.InternalEditorUtility.HierarchyWindowDragByID(0, UnityEditorInternal.InternalEditorUtility.HierarchyDropMode.kHierarchySearchActive, null, false);
does not work.

Could you please submit a bug report? That’s the safest way to receive an answer to this problem in this case and if it turns out to be an issue it will already be in the appropriate pipeline.

(Case 1167675)

1 Like

Thanks for the bug report! QA was able to reproduce the issue and it has been forwarded to the developers. You will be able to find the current resolution state here in a couple of hours: Unity Issue Tracker - GameObjects in Hierarchy window are not hidden when using HideFlags.HideInHierarchy

Great! That was a quick task for a Friday. :slight_smile:

1 Like