Using EditorGUILayout controls in OnSceneGUI()

I'm implementing a simple level editor that functions in the scene view. For the most part it's working fine, but there seem to be some controls that, while they work correctly in OnInspectorGUI(), don't work correctly in OnSceneGUI().

The two controls I'm having trouble with are Popup() and ColorField(). It seems that with these controls, the selected value is not returned to the caller when the control is used in OnSceneGUI().

Here's the code I'm using to test this:

using UnityEditor; 
using UnityEngine;

public class MyScriptEditor : Editor
    int selected = 0;
    Color color = Color.white;

    void OnSceneGUI()
        if (Event.current.type == EventType.Layout) {

        selected = EditorGUILayout.Popup(
            selected, new string[] { "0", "1", "2" });
        color = EditorGUILayout.ColorField(color);

The value returned is always the initial value (0 and Color.white, respectively), regardless of what's selected in the control.

Should these functions be expected to work in this context? Can anyone see any obvious problems with the example code above?

(Should be a comment, but I need code formatting.)

For a target component that adds GUI overlays, it's tempting to do this in your editor to make your scene view emulate your game view ...

public void OnSceneGUI()

This may work, but it's easy for your OnGUI method to start making assumptions and calls that are not supported in edit mode, so be careful.

I could be wrong, but I believe the only reason you can do `OnSceneGUI()` in the editor is to catch the Gui Events which are accessible through the `Event` class (i.e. `Event.current.use` or something like that).

Additionally, the GUI functions in EditorGUI are primarily used for wizards and custom inspectors, and are not to be used to paint directly onto the scene view in Unity. Also, there is no identical "Popup" or "ColorField" component in the standard game GUI class, so I'm pretty sure Popup and ColorField are only supposed to be used within custom inspectors, editor windows, and wizards, and not in scene GUIs.

If you're trying to create a custom editor within Unity, it is highly recommended that you use a custom EditorWindow, and not paint directly onto the scene view, because, as you just found out, not everything is supported, and it's not really a "best practice" for Unity.