CheckOnGUI broken?

Heh… Unity’s EditorGUI has plenty of bugs, but this one is just making me INSANE!!!

ArgumentException: You can only call GUI functions from inside OnGUI.
UnityEngine.GUIUtility.CheckOnGUI () 
UnityEngine.GUILayoutUtility.DoGetRect (UnityEngine.GUIContent content, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) [0x00000]
UnityEngine.GUILayoutUtility.GetRect (UnityEngine.GUIContent content, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) [0x00000]
UnityEditor.InspectorWindow.OnGUI () 
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000]

As you can see from the call stack, the code is being run from OnGUI().

I get this error when the user pops up the color selection dialog in my custom Editor class. Inside of the OnInspectorGUI method I have something like the following:

fieldValue = EditorGUILayout.ColorField( fieldLabel, (Color)fieldValue );

I can work around the issue by providing a custom color inspector, but that’s a lot of work to do something that’s supposed to be a built-in feature.

Has anyone else come across this problem, and if so, have any tips you’d care to share?

.

Can you post the code that is giving you this error? (May be possible to see what is tripping the editor up.)

I created a new class which inherits from EditorWindow (rather than Editor) so that I can get dock/undock behavior, copied and pasted the code from the old Editor into the new EditorWindow, and the problem with the EditorGUILayout.ColorField() is gone.

This would seem to indicate a problem unique to the Editor class, but to be honest I’m no longer motivated to find out for sure. I now have a better user experience with the dockable EditorWindow and the problem isn’t exhibiting in the new implementation despite using identical code.

Thank you for taking the time to respond, I appreciate it.

.

I got this same error the other day.

Basically I was creating a new custom inspector, and within it there was a button you click to launch a custom EditorWindow.

public override void OnInspectorGUI() {
		DrawDefaultInspector();
		if (GUILayout.Button("Edit")) {
			// Launch the editor window..
			EditorWindow.GetWindow(typeof(MyEditorWindow)).Show();
		}
	}

‘MyEditorWindow’ in this case is just a new empty class inheriting from EditorWindow. When you click the button, the window pops up like expected - but you get that error as well.

Actually I just found another post on the issue - it does appear to be a bug.

http://forum.unity3d.com/viewtopic.php?t=46416&highlight=call+gui+functions+inside+ongui

You know, I had seen that post before, and it helped me resolve another issue, but it didn’t occur to me that it would apply here as well. Thanks, that’s good to know!

Edit : Actually, it doesn’t really apply to my exact situation, at least not directly, since it’s Unity’s GUI code itself displaying the dialog (the ColorField() method handles that internally), but it at least seems to indicate the cause and something for the Unity team to review.

.