- Home /
GUI: Windows inside Windows
Is it possible to have a window generated by pressing a button (from a set of buttons which produces only one window at a time) inside a generated window?
I can't find a way to get this to work. Sometimes some of the buttons create a window, while other times they just don't work.
I have created a unity package with a minimalistic test scene where this problem occurs. You can download it here:
http://feupload.fe.up.pt/get/MhGJhplt45EjkFP
EDIT - Example 2: I have just reduced this to the simplest case possible, a window inside a window. This correctly renders both of the windows, but it still shows a runtime error on the console. I suppose Unity can't handle Windows inside Windows.
using UnityEngine;
public class Test : MonoBehaviour {
void OnGUI() {
GUILayout.Window(0, new Rect(0, 0, 200, 300), OnGUIWindow, "Parent");
}
void OnGUIWindow(int windowID) {
GUILayout.Label("Parent");
GUILayout.Window(1, new Rect(0, 0, 100, 150), drawWindow, "Son");
}
void drawWindow(int windowID) {
GUILayout.Label("Son");
}
}
Errors:
InvalidOperationException: Hashtable.Enumerator: snapshot out of sync.
ArgumentException: Getting control 0's position in a group with only 0 controls when doing Repaint
Why do you need a window inside an other window?, I don't get it, it's to use in a game or an editor script?, because if it's for a game you don't need that, it's better to use individuals windows than one inside another, it's my point of view of course.
this is not intended for a typical game. it's more like a 3d viewer. in this particular case there is a filter window with layers/groups of models, and I'm trying to implement a color picker to set the color of each layer/group... a window (color picker window) inside a window (layers/groups window). anyway I've managed to workaround this problem by creating a Windows$$anonymous$$anager concept where I add new windows whenever I want to show a new dialog. but still, it's a strange limitation of Unity imo.
Nested windows make perfect sense, for screen real-estate management if nothing else. Child window ought to be positioned relative to the parent (and drag with it, etc.) But you're right, it doesn't appear to work this way -- I get the same error you mention above (with Unity 3.5.2f2).
Same for me. Don't understand why so, this is quite annoying. That kind of exception occurs when you remove an element from a list you're iterating through.
Answer by GregBlast · May 15, 2016 at 02:59 PM
When I decided to make a drop-down control I chose to make a popup manager which is a MonoBehaviour of its own and is in charge of rendering any popup window that is open. Thanks to "GUI.BringWindowToFront" it can keep the popups above the window onto which the drop-down control is placed.
So basically I have a TextField and a Button. When the button is pressed it registers a popup to be opened below the TextField. This way the window can overlap anything defined below in the layout and also get out of the main window bounds.
I've made a few videos already. It works pretty well I think.
Your answer
![](https://koobas.hobune.stream/wayback/20220613041302im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GUILayout Window Help 1 Answer
How to change thickness of ScrollBar of GUILayout ScrollView? 0 Answers
GUILayout formatting help 1 Answer
GUILayout Textfield not editable just static 1 Answer
Using treeview OnGUI with GUIlayout 0 Answers