Setting depth of a Window

I have a simple script for mouse cursor replacement, set at depth 0.
All my other GUI scripts are at higher depth.

But unfortunately, windows are still drawn on top of my cursor… setting a high depth before GUI.Window or inside the window function has no effect.

… any ideas?

If your mouse replacement is done via OnGUI(), then it will always appear behind all GUI.Window calls.

Damn, I was afraid of that… it sucks!
So that means I have to use an ancient GUIText, like the wiki script, right?

OnGUI is always drawn on top of everything, including GUITextures. I think some kind of custom cursor function is necessary, where it’s not covered by anything.

–Eric

I have an ingame console that blacks out the entire screen by a function like this:

function OnGUI()
{
	if( !isEnabled )
		return;
	
	GUI.depth = -255;
	
	GUILayout.BeginArea( Rect(0,0,Screen.width,Screen.height), "", "box" );

...

	GUILayout.EndArea();
}

The entire screen (including all my gui windows) gets blacked out nicely. As a side bonus, I can still click through the black box to interact with those windows.

Haven’t done any testing, but I am sure you could just make a custom cursor style and apply it instead of “box”.

Cool, didn’t think of that :slight_smile: As far as I know, setting GUI.Depth to anything less than 1 will draw it over GUI.Windows. Interestingly the documentation doesn’t mention the overlap between OnGUI and GUI.Window depths.

Thanks guys… this depth thing sure is obscure and ill-documented!
I thought negative depth had no effect, I even filed a bug about this when 2.0 came out, maybe they changed it?
I sure wish they’d used the more traditional z-index convention… but if depth can be negative after all, the result is the same, so that’s cool :slight_smile:

I don’t really understand that… you said earlier:

… which is it?

Anyway, it turns out I didn’t explicitly set GUI.depth in my mouse cursor script, assuming it would be 0 by default… but in fact, it seems that GUI.depth isn’t reset between scripts, so my cursor used the depth set by the last running script!
Now I’m setting it to 0 explicitly and my cursor does appear on top of my windows.

I’m filing a bug asking for clarification… let’s all file one to keep the pressure up :wink:

@Ben
So by default, everything you put in OnGUI renders behind windows, unless you specify a GUI.depth of less than 1, and then the controls immediately after the depth setting will appear over your windows. Sorry about the ambiguity.