Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

OnSceneGUI is not called for scriptable object editor

Discussion in 'Scripting' started by paragboro, Nov 16, 2012.

  1. paragboro

    paragboro

    Joined:
    Oct 30, 2012
    Posts:
    1
    [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..
     
  2. Aberdyne

    Aberdyne

    Joined:
    Mar 17, 2015
    Posts:
    64
    Code (CSharp):
    1. void OnEnable()
    2. {
    3.     SceneView.onSceneGUIDelegate += OnSceneGUI;
    4. }
    5.  
    6. void OnDisable()
    7. {
    8.     SceneView.onSceneGUIDelegate -= OnSceneGUI;
    9. }
    10.  
    11. void OnSceneGUI(SceneView sceneView)
    12. {
    13.     // your OnSceneGUI stuffs here
    14. }
     
  3. bobbyjoe6128

    bobbyjoe6128

    Joined:
    Nov 19, 2013
    Posts:
    2
  4. lindsaytalbot

    lindsaytalbot

    Joined:
    Sep 11, 2015
    Posts:
    28
    Signed in just to say you're a legend and saved me after 2 hours of trying to come up with a solution
     
  5. Radiangames2

    Radiangames2

    Joined:
    Aug 22, 2012
    Posts:
    45
    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
     
  6. Dom_Laflamme

    Dom_Laflamme

    Unity Technologies

    Joined:
    Sep 25, 2013
    Posts:
    27
    onSceneGUIDelegate is deprecated and was replaced with duringSceneGui

    Code (CSharp):
    1. void OnEnable()
    2. {
    3.     SceneView.duringSceneGui += OnSceneGUI;
    4. }
    5. ...
    6. void OnSceneGUI(SceneView sceneView)
    7. {
    8.  
    9. }
    10.  
     
  7. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    12,898
    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
     
  8. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    223
  9. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    12,898
    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