OnSceneGUI is not called for scriptable object editor

[CustomEditor(typeof(LevelData))] // Where LevelData is derived from ScriptableObject
public class LevelEditor : Editor
{

public override void OnInspectorGUI()
{
base.OnInspectorGUI();
}

public void OnSceneGUI ()
{

}
}

I am creating a level editor for my game but OnSceneGUI is not called if my LevelData is ScriptableObject. I need to have LevelData to be ScriptableObject. How do i draw in the sceneview using editor class…

void OnEnable()
{
    SceneView.onSceneGUIDelegate += OnSceneGUI;
}

void OnDisable()
{
    SceneView.onSceneGUIDelegate -= OnSceneGUI;
}

void OnSceneGUI(SceneView sceneView)
{
    // your OnSceneGUI stuffs here
}
7 Likes

thanks.

Signed in just to say you’re a legend and saved me after 2 hours of trying to come up with a solution

Also wanted to say thanks. Recently discovered the power of Handles and OnSceneGUI for editing data in sceneview, and glad to see we can use them on ScriptableObjects in addition to MonoBehaviours.

Luke

onSceneGUIDelegate is deprecated and was replaced with duringSceneGui

void OnEnable()
{
    SceneView.duringSceneGui += OnSceneGUI;
}
...
void OnSceneGUI(SceneView sceneView)
{

}
4 Likes

Hi,

Is it not possible to use OnSceneGUI like before, without register it in OnEnable ?

Like described here

https://docs.unity3d.com/ScriptReference/Editor.OnSceneGUI.html

Thanks

For those having the issue of the standard OnSceneGUI method (called via messaging) not being called at all, unrelated to using a delegate callback, check this issue: Unity Issue Tracker - OnSceneGUI is not being called when using a certain layout

It may happen if you have a “corrupted” layout, I added a comment on the issue page with a few workarounds.

I can confirm in many cases all it takes is restore to the default layout to solve an issue where an editor script is not running as it should