Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

OnSceneGUI stop been called after a generic script is updated

Discussion in 'Immediate Mode GUI (IMGUI)' started by Max_power1965, Aug 31, 2017.

  1. Max_power1965

    Max_power1965

    Joined:
    Oct 31, 2013
    Posts:
    127
    Hello guys,
    I have an EditorWindow script which is attached to the onSceneGUIDelegate:

    Code (CSharp):
    1. void Awake()
    2. {              
    3.     SceneView.onSceneGUIDelegate += this.OnSceneGUI;
    4. }
    5.  
    6. void OnSceneGUI( SceneView sceneView )
    7. {
    8.     DrawCellCenterPoints(this._maze,_mazeMargin);
    9.     DrawCellSelection();          
    10. }
    The code works fine and the OnSceneGUI is called, the problem is that as soon as I change some script in the project, even a blank line in a random script, the callback stop to be called.

    To fix the problem I have to close the windows and reopen it again. I tried this solution but it didn't work.
    Any Idea how to solve the problem without having to close and reopen the window every time? I'm quite new with editor scripting so maybe I'm missing something.
     
  2. Max_power1965

    Max_power1965

    Joined:
    Oct 31, 2013
    Posts:
    127
    Found the solution:
    Awake is not called after hot reloading. you can subscribe to the event in OnEnable and unsubscribe in OnDisable
     
  3. marijnz

    marijnz

    Joined:
    Sep 20, 2012
    Posts:
    67
    an EditorWindow is a SerializableObject that persists through play/edit mode. Awake is only called when the window is created. But you figured that out already :) If you look in the EditorWindow source code, you can see that the hideFlags are set to "DontSave". That causes that ;)