- Home /
Popup Window from an EditorWindow?
I'm trying to create a sub-window for an EditorWindow that the user can move around. Something like the built-in AnimationCurve
Editor Window. I've tried two separate ways so far but to no avail. To quickly rehash:
GUILayout.Window - I attempted to use the GUILayout.Window function. This worked well until I realized that if it was positioned over other controls, those would take precedence because of how the IMGUI event system handles input. So I attempted to move the code to the top of my
OnGUI
call but that didn't work because the popup started drawing below the normal controls. I then tried overridingEvent.current.type
at the beginning if it was a mouse event within the window's Rect and then reset it right before theGUILayout.Window
call but that didn't work either. I assume thatEvent.current.Use()
does something internally other than change the type.PopupWindow.Show - I attempted to use the poorly documented PopupWindow system. I subclassed PopupWindowContent and used
PopupWindow.Show
to display it. I always get an exception of the typeUnityEngine.ExitGUIException
, regardless of whether I call it inOnEnable
,OnGUI
, orUpdate
.
NOTE: #1 above would create a pop-up that cannot leave the EditorWindow
and #2 would create a pop-up that's separate from the EditorWindow
. Either is fine.
Has anyone else accomplished something like this? Does anyone have any ideas on how to do this?
Answer by SonicBloomEric · Feb 11, 2015 at 05:47 PM
[I posted a similar question to the Beta list and got a response there. I'm going to answer my own question here with information gleaned from that conversation in case anyone else comes across this while trying to solve a similar problem.]
The best way to do this (see: Color Picker or Object Picker popup windows) is to create a new Utility Window and have it interact with the main window. This is accomplished by calling the EditorWindow.ShowUtility method (there's an example in the documentation at that link).
As a clarification regarding the PopupWindow
system, it appears to be linked to the EditorWindow.ShowPopup method call; a shortcut, if you will. Another possibly(?) related and definite shortcut would be EditorGUI.Popup. These all appear to do something very similar: create a hovering context that's locked to a specific location (or GUI Control). Adding to the confusion, EditorWindow.ShowAsDropDown also exists and does nearly the exact same thing as ShowPopup...
Hopefully Unity will update the documentation to make distinctions and examples more clear.
Your answer
![](https://koobas.hobune.stream/wayback/20220613183009im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is it possible to have a spectrum analyzer display for each song in a playlist? 1 Answer
individual object menu 0 Answers
Overlapping GUI Button priority 3 Answers
GUI Popup problem…! 1 Answer