- Home /
How to control the UI and OnGUI elements display order?
I have a scene GUI with elements generated in OnGUI function and have just added UI elements from the new 4.6 UI menu system. How to make the UI elements appear on top of the OnGUI elements?
hmm, considering your popularity in the forums, I assume you know that its wiser to be consistent either new UI or OnGUI.
I guess it might not make sense to use both UI and OnGUI in a single $$anonymous$$onoBehaviour, but I am just wondering how the OnGUI and UI elements could coexist in a single scene.
I haven't seen this in the documentation anywhere. I would suggest a quick trial. The results should be consistent with one always ending up on top.
Answer by tomekkie2 · Dec 07, 2014 at 11:16 AM
I have found a way, but requires setting canvas.RenderMode to WorldSpace and setting a separate camera to render the canvas. The steps are:
1.Setup the canvas.RenderMode to WorldSpace
2.Place an aditional camera to the scene with:
Clear Flags set to Depth Only
Culling Mask set to UI 3.Uncheck UI in the MainCamera Culling Mask
4.At the end end of the OnGUI function put: additionalCamera.Render();
All that results in canvas being rendered on the top of OnGUI elements