- Home /
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:
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;
}
}
}
Well, i don't really get what's your actual goal. When and why do you want to set the hideflags to NotEditable? I think the main problem is that you set the hideflags for the GameObject and not for it's components. You shouldn't set it for the GameObject at all.
You should add more details about your script and what you actually want to do. Is this used in a plain editor script, an EditorWindow, PropertyDrawer, custom inspector?
I wrote a tool to allow designers at our company to edit prefabs by double clicking them in the project window. It opens up a new scene with that prefab instantiated. The designer can then modify the prefab to their liking and hit a button to save it back to the project asset.
$$anonymous$$y goal with this particular hideFlags feature was to reduce the chance for designer error by only allowing the prefab that is currently instantiated in the scene to be editable. Any prefabs in the project window should not be editable during this time.
After grabbing out the child components and setting the hideFlags on each of them directly and not the gameObject itself, it looks like it fixed the visual error that was happening, and still fufils my requirement. Thanks for the help! :D (You can go ahead and write an answer if you'd like, I'll accept it.)
Answer by Bunny83 · May 07, 2015 at 10:11 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613185730im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to record hideFlags for Undo/Redo 0 Answers
Editor: How to display properties in inspector based on enum in same script ? 1 Answer
missing (transform) vs none: how to code this or query for it? 1 Answer
Custom Inspector Enum 1 Answer
Custom ordering of variables in inspector when using base and derived classes 1 Answer