- Home /
GameObject on top of GUI
I got some GUI Textures, buttons and text in the screen and I want a GameObject to appear in certain occasions(for example, on a click). The things is that the GameObject is render UNDER GUI and not ON TOP.
On this post http://answers.unity3d.com/questions/15386/gameobject-over-gui.html Eric suggests a solution. Anyone got another idea or could explain me how to implement Eric's solution? Because I see that this is a recurrent problem!
Thanks! :)
Answer by saschandroid · Sep 17, 2014 at 10:08 AM
Add a new Layer tag "gui".
gui elements: Set Layer of your gui-elements to "gui"
(first)gui camera: set Culling Mask to "gui" only
add second camera (object camera at the same position as the first camera)
object camera: set Clear Flags to "Depth only".
object camera: set Culling Mask to everything except "gui"
object camera: set Depth to a higher value than gui camera (e.g. gui camera -1, object camera 0)
object camera: uncheck GUILayer
Answer by Anxo · Jan 06, 2012 at 08:30 PM
All he is saying is make a second camera, give it a higher dept than the first camera and set it to dept only. Have the GUI on the lower dept camera and the game object in the higher dept camera. Win.
Ok... so...
1) Witch camera should I set to "Depth only"?
2) How do I put de GUI on one camera and the GameObject in another?
Thanks! :)
It looks like you should read this http://unity3d.com/support/documentation/Components/class-Camera.html
just imagine 2 cameras next to each other, one is looking at box A at position x=0, y=0, z=0. The other is looking at box B at position x100 y100 z100. If the first camera is set to depth 1 and the second is set to depth 0 and the first camera is set to depth only, When you hit play, you will see both boxes in the scree. 2 images are rendered by placed on top of each other like paper.
Perfect!!! So, if one camera is looking to 100,100,100 should I put the gameobject in that position, don't I? Thanks for helping a newbie! :)
Still can't do it. I follow your steps but nothing happens. The GameObject is still rendered behind the GUI.
Remember to set rendering path to Forward on both cameras
Answer by mononull · Mar 21, 2013 at 09:08 PM
Add second camera, set it to a higher depth, and set clear flags to depth only. If you still have issues you may be forgetting another step. Remove the GUILayer component from the second camera you added if it was there by default. Now this camera will draw the 3D model on top of the other camera drawing the GUI.
Your answer
![](https://koobas.hobune.stream/wayback/20220613062728im_/https://answers.unity.com/themes/thub/images/avi.jpg)