Weird Issue: GUI Menu System

Hi,

I am working on an App that contains a GUI with 6 buttons. One in each corner and one in the top middle, one in the bottom middle. When I click a button on the bottom of the screen, I get the initial menu drawn properly. When I click on a button in that menu, the GUI is reset and then a new sub-menu should be drawn in the exact same space as the previous menu. The second menu is not being drawn.

This code draws the initial menu and works just fine…

if (drawBottomRightMenu) {
		Debug.Log ("brmenu: x=" + (Screen.width - (maxMenuWidth + 10)) + ", y=" + (Screen.height - (maxMenuItemHeight*3+32)) + ", width=" + maxMenuWidth + ", height=" + (maxMenuItemHeight*3));

		// Make a background box
		GUI.Box (Rect(Screen.width - (maxMenuWidth + 10),Screen.height - (maxMenuItemHeight*3+32),maxMenuWidth,maxMenuItemHeight*3),"");

The Debug.Log prints “brmnu: x=350, y=243, width=120, height=45”

The code for the sub-menu is…

if (drawBGSelection) {
        Debug.Log ("bgselection: x=" + (Screen.width - (maxMenuWidth + 10)) + ", y=" + (Screen.height - (maxMenuItemHeight*3+32)) + ", width=" + maxMenuWidth + ", height=" + (maxMenuItemHeight*3));

		// Make a background box
		GUI.Box (Rect(Screen.width - (maxMenuWidth + 10),Screen.height - (maxMenuItemHeight*3+32),maxMenuWidth,maxMenuItemHeight*3),"");

The Debug.Log prints “bgselection: x=350, y=243, width=120, height=45”, but the box and subsequent buttons do not appear on the screen. I tested for screen width, and it showed as 480 for both functions. I tried with the bottom left and was unable to display a menu there either, however the menus and sub-menus at the top of the screen display just fine. The x and y positions is hard-coded for the top left, and x is dynamic for the top-middle and top-right menus.

I have tried saving the GUI.depth, temporarily adding 50 to it for the sub-menu and then changing it back to no avail. I tried hard-coding the menu to the same values used for the top-left menu and sub-menu that works fine, but that didn’t work either.

Any ideas??

This may help (as i had the same problem today)

Higher GUI.depth values push gui objects further away from the camera and make them appear behind other gui objects. If you want the submenu to appear in front of the regular menu, the submenu should have a GUI.depth of 0 and the regular menu should have a GUI.depth of 1. It was counter intuitive for me as well.

Hope that helps!

I’m an idiot.

Thanks for the response Bongo. This didn’t fix it, but I did have an itty bitty DOH moment.

I’m actually wiping the first menu off before putting up the second. Basically, I display the button. If clicked, I reset my GUI and the set a bool to draw the next menu to true. Then when OnGUI goes through the next iteration, the new menu is drawn on a blank canvas. I know its getting this far, because I’m getting the Debug.Log entries that are written from the if block that is supposed to draw the sub-menu.

Its really quite strange. I’ll attach the script file, so anyone willing to take a look can see what I’ve done and hopefully help me figure out what I’m missing.

194186–6913–$armorgui_188.js (16.4 KB)

Hi,

Did you update to Unity 2.5.1? There was a problem with GUI.Depth in 2.5.0

http://unity3d.com/unity/whats-new/unity-2.5

Other Fixes:
Various scripting reference documentation fixes
GUI.depth now works again

Hi David,

Thanks for the response. I have Unity 2 Indie version 2.5.1f5 (24931).