- Home /
GUI.depth factors
Are there any other factors that control the depth of GUI elements? I currently have a few GUI.Windows in my scene, and one window is always showing above other windows even though its depth is far below the others.
I have the same setup in other scenes, with the same exact GUI.depth settings and its working fine.
I would like to note that group of windows that are being drawn over are all grouped together in the same script. The window drawing over said group is in a separate script.
Thanks
did you try writing the GUI code at the start? They tend to be drawn in the order that they are scripted
The window element that is being drawn above the other elements is in another script altogether. GUI.depth is there so that you can have gui elements in the same scene at the same time but at different depths and in turn you then do not have to worry about order of render.
every OnGUI call (even if it's empty) has an overhead so it makes sense to have all your GUI scripts in one place
OnGUI can be expensive but this is one of those times that I needed to have GUI elements from different scripts. It just makes my life much easier and GUI is suppose to support depth control. Right now I am using GUI.BringWindowToFront to the element I need on top.
Answer by Daniel-Brauer · Jul 30, 2010 at 06:33 PM
GUI.Window sorting happens differently from other GUI areas, and as you've discovered, it ignores GUI.depth. The only way you can sort GUI.Windows from a script is by using GUI.BringWindowToFront() and GUI.BringWindowToBack(). If you need to sort all of your windows, you would have to keep track of their unique IDs and call one of these functions on all of them in order.
Your answer
![](https://koobas.hobune.stream/wayback/20220613055143im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Displaying a gameobject over gui issues 0 Answers
gui elements truncated by parent 0 Answers
UI Button order 1 Answer
useGUILayout=false does not honor GUI.depth 0 Answers
How to use GUI.depth to bring a GUI.Box in front of other GUI elements? 1 Answer