hideFlags in prefab children not updating

This is killing me, when setting hideFlags on a child of a created prefab from the editor. The child doesn’t update.

e.g

using UnityEditor;
using UnityEngine;

public class HideWindow : EditorWindow {

    private GameObject source;
    private GameObject gameObject;

    [MenuItem("Window/HideWindow")]
    private static void Open() {

        HideWindow window = EditorWindow.GetWindow<HideWindow>();
        window.Show();
    }

    void OnGUI() {

        source = EditorGUILayout.ObjectField(source, typeof(GameObject), false) as GameObject;

        if (GUILayout.Button("Create") && source != null) {

            gameObject = PrefabUtility.InstantiatePrefab(source) as GameObject;
        }

        if (GUILayout.Button("Hide") && gameObject != null) {

            Toggle(gameObject, HideFlags.HideInHierarchy);
        }

        if (GUILayout.Button("Show") && gameObject != null) {

            Toggle(gameObject, HideFlags.None);
        }
    }

    private void Toggle(GameObject gameObject, HideFlags hideFlags) {

        foreach (Transform child in gameObject.transform) {

            child.hideFlags = hideFlags;

            //child doesn't change
        }
    }
}

Any ideas?

ok so looks like you need to set EditorUtility.SetDirty(gameObject) to force the refresh

1 Like