Bug with displaying components in Inspector after hideFlags.NotEditable?

Hey everyone! I’ve been running into a strange bug lately, maybe someone has seen something like it before.

In messing around with object hideFlags, (specifically NotEditable), I’ve managed to break the inspector. What appears is this:

What I expect is this:

42262-screen-shot-2015-03-10-at-113803-am.png

It seems like toggling the hide flags on and off sometimes fixes the issue, but has anyone else run into this before and have a reliable fix?

Here is the code I’m using to do the toggle:

private static void ProjectWindowItem_OnGUI(string guid, Rect drawingRect) {
    GameObject asset = (GameObject)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath (guid), typeof(GameObject));
    if (asset) {
        if (PrefabEditor.IsEditing()) {
            // Set the NotEditable flag. (| bitwise or)
            asset.hideFlags = asset.hideFlags | HideFlags.NotEditable;
        } else {
            // Clear the NotEditable flag. (& bitwise and) (~ bitwise negate)
            asset.hideFlags = asset.hideFlags & ~HideFlags.NotEditable;
        }
    }
}

The hideflags are a bit tricky. While they are available for every UnityEngine.Object derived type not all combinations work or make sense for every type. You usually don’t want to use NotEditable on a GameObject, only on components.

If you want to prevent editing in general you might want to set it to HideInInspector and HideInHierarchy. Though be careful with those since you can litteraly hide assets / objects from the project.