Create a greyed out value field in the editor?
I am writing an editor window to help me automate some tasks. Basically, in some cases I want to create a greyed out (non-interactive) field instead of the regular one, if changing the value doesn't make sense.
Here's an example from the Unity preferences window:
I could not find any clues online, but I imagine it can be done in a custom window as well. Any clues?
Answer by LukaKotar · Dec 23, 2015 at 12:27 AM
I was able to find the answer. Basically, set GUI.enabled to false, and then back to true after displaying the field(s).
GUI.enabled = false;
// Your greyed out GUI
GUI.enabled = true;
Another solution:
[CustomEditor(typeof($$anonymous$$yScript))]
public class $$anonymous$$yScriptEditor : Editor
{
public override void OnInspectorGUI()
{
collider.enabled = EditorGUILayout.BeginToggleGroup("Enable Collider", collider.enabled);
// Your greyed out GUI
EditorGUILayout.EndToggleGroup();
}
}
Answer by PROE_ · Jan 02, 2020 at 09:54 PM
For others, probably the best solution is EditorGUI.BeginDisabledGroup(bool)
When I use that is says the name EditorGUI.BeginDisabledGroup does not exist in the current context. ?
Then you're doing something wrong. Are you sure that you actually try to use this in an editor script and that you have a using UnityEditor;
at the top of your script? Note that this does not work in a runtime script. The UnityEditor namespace does only work for editor scripts.
According to the documentation EditorGUI.BeginDisabledGroup and the corresponding EditorGUI.EndDisabledGroup are still there.
How do you make a script an editor script and not a runtime script?
There's this tutorial in the docs that should get you on track: https://docs.unity3d.com/$$anonymous$$anual/editor-CustomEditors.html
Your answer
Follow this Question
Related Questions
GUİ Editor Window input 0 Answers
Editor Int sliders affecting each other 0 Answers
Custom EditorWindow indicator 0 Answers
Making a custom editor window much like the Animator window? 0 Answers
EditorWindow fields are too far away from each other 0 Answers