Script for locking/unlocking objects, hierarchy update wrong

I wrote a quick editor class for locking and unlocking level geometry. However, when I toggle an object’s visibility using HideInHierarchy, the Hierarchy view itself does not seem to update until I actually run the game.

Can anyone see what I’m doing wrong?

using UnityEngine;
using UnityEditor;

public class LockUnlockGameObjects : ScriptableObject
{
    [MenuItem("Edit/Lock selected object %l")]
    static void LockObject()
    {
        int total_locked = 0;
        HideIncludingChildren(Selection.activeTransform, ref total_locked);
        Debug.Log("Locked " + total_locked + " objects");
    }

    //this enables the button
    [MenuItem("Edit/Lock selected object %l", true)]
    static bool LockObjectValidate()
    {
        return Selection.activeGameObject;
    }

    [MenuItem("Edit/Unlock all locked objects %#l")]
    static void UnlockAllObjects()
    {
        int total_unlocked = 0;
        Object[] targets = FindObjectsOfType(typeof(GameObject));
        foreach (GameObject target in targets)
        {
            if (target.hideFlags == HideFlags.HideInHierarchy)
            {
                target.hideFlags = (HideFlags)0;
                total_unlocked++;
            };  // else nothing to unhide
        }
        Debug.Log("Unlocked " + total_unlocked + " objects");
    }

    static void HideIncludingChildren(Transform root_transform, ref int total)
    {
        if (root_transform.gameObject.hideFlags == (HideFlags)0)
        {
            root_transform.gameObject.hideFlags = HideFlags.HideInHierarchy;
            total++;
        };
        foreach (Transform transform in root_transform)
        {
            HideIncludingChildren(transform, ref total);
        }
    }
}

This bug has been logged and is being investigated.

thanks andeeee!

We managed to get it to behave as we want it to, what it needed were some EditorUtility.SetDirty calls in the appropriate places and now they all lock/unlock correctly. We finally have what’s called freeze/unfreeze in other editors.

I’m also having issues using this hideflag, no matter what I do (Including SetDirty) the objects are still shown the hierarchy. Is this the same bug? Hitting play does nothing in my case.