GUI render order.

Is there a way to control the order in which GUI is drawn?

Say i have two game objects A and B who draws their own gui GA and GB using the OnGUI method. Now i want to make sure that GA is always drawn ontop of GB is there a way to control this?

Regards,
Marc

I think you would set the depth of the gui.

function OnGUI ()
{
     // This will be drawn below
     GUI.depth = 2;
     GUI.Box (Rect (), "Box");
     
     // This will be drawn on top
     GUI.depth = 4;
     GUI.Box (Rect (), "Box2");
}

Thanks!

That works, but you seem to have reversed what will be on top. Lower numbers seem to go infront og higher.

Actually, that won’t quite work when you throw input into the mix.

Then you either need to use Window (if you want click-to-bring-to-front behaviour), or put your two pieces of GUI into seperate scripts, then set the depth of each script.

That is what i did as my gui is component based and each component can create its own gui to control it :smile:

Thanks for the help all.

Cheers,
Marc