- Home /
Prefix label greyed out when following component disabled
I have a problem where a prefix label in a custom inspector gets greyed out when only the first following component is disabled. How can I fix this? I have tried adding a pseudo-component with zero width before the disabled component, but it still takes up some spaces and creates a glitched look.
Example: http://i.imgur.com/xa6Nytt.png
Here you can see the prefix label turns grey because the following component is disabled, even when explicitly enabling the GUI beforehand:
EditorGUILayout.BeginHorizontal ();
GUI.enabled = true; // This has no effect
EditorGUILayout.PrefixLabel ("Grid snapping");
GUI.enabled = mb.gridOption > 0;
bool decrement = GUILayout.Button ("-", layoutOptions);
GUI.enabled = true;
// ...
EditorGUILayout.EndHorizontal ();
What might I be able to do about this?
Answer by puetsua · Oct 21, 2019 at 10:48 AM
I had same question but I couldn't find a good answer with Google. So here is a way I found to fix this problem:
Replace
EditorGUILayout.PrefixLabel ("Grid snapping");
With
EditorGUILayout.LabelField ("Grid snapping", GUILayout.Width(EditorGUIUtility.labelWidth - 4));
I don't know if it is a good way to do, but this one seems work. I use Unity 2018.3.14f1.