GUI window gets drawn behind other gui elements.

This a strange bug where GUI window of mine gets drawn behind other elements of gui.

PS: all the elements are drawn from same file and irrespective of the GL contents, it still gets drawn behind the other elements. especially begin groups / boxes. Tried everything from changing drawing order.

without the code i can unfortunaly not really help but i think it may help if i tell you that the gui elements are drawn in the order you type the code

for example

draw gui A;

draw gui B;

itll first draw gui A and then gui B on top of it

It is some bug with unity or the way GUI windows work! i dont know but the problem was with events of unity3d, When GUI Layout is getting called, the GUI window is supposed to be drawn, otherwise the window wont be displayed. And also repaint for the window gets calls as soon as first call to GUI.Window is being made that is the layouting event, so the window gets drawn first and then the other objects repaint event, hence the window goes behind everything.

this doesnt happen when I tried to call the whole gui from same script! But happens when i have the gui components across different scripts and try to call all of them from a single ongui.

And i solved it by using this

if(e.type == EventType.layout)
	return;

for other components and by calling GUI window as the last call.

Still not clear on why this happens but will mark this as answer until i get an exact one!