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

GUI calls from within OnSceneGui() no longer working in 5.0.0f4

Discussion in 'Editor & General Support' started by OliverAnthony, Jun 22, 2015.

  1. OliverAnthony

    OliverAnthony

    Joined:
    Nov 21, 2012
    Posts:
    13
    I have been using custom Editors and Editor Windows for years. I've needed to create and use one again for the first time since upgrading to Unity v5, and I'm getting some super strange results that I've never encountered before.

    Code (CSharp):
    1.  
    2. [CustomEditor(typeof(LayoutObject))]
    3. public class LayoutAssistant : Editor {
    4.         void OnSceneGUI () {
    5.                if (GUILayout.Button ( "Test" ) ) {
    6.                      //whatever
    7.                }
    8.         }
    9. }
    This results in an extremely wide (much wider than it needs to be to fit the string passed to the method) button being drawn seemingly in the Canvas space (???) of the SceneView (when I zoom out, the button scales, when I pan, the button moves around with the rest of scene). All this, except only in the upper right quadrant of the SceneView. If I pan far enough that the button moves into any of the other quadrants, it simply gets cut off, eventually disappearing entirely.

    Any ideas? Did I miss an important PSA on changes to using GUI calls in the SceneView?
     
  2. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    If i do recall coreectly (I am on my phone) you need to tell Unity that you wany to draw gui in the scene. Take the code below

    Handles.BeginGUI ()
    //GUI code
    Handles.EndGUI ()

    I am 90% sure from memory that is what you are missing.

    Cheers,
     
    OliverAnthony likes this.
  3. OliverAnthony

    OliverAnthony

    Joined:
    Nov 21, 2012
    Posts:
    13
    That was the ticket.

    Don't have any of my old scripts at this workstation. I was killing myself on this, thanks!
     
  4. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    You are very welcome :)