I used a canvas and Unity UI elements as a HUD. I want HUD to be in front of everything but it's not.
2 Answers
Haven't worked with Cardboard before but I beleive you can fix this with camera culling. Just follow the steps below:
Canvas:
1.Select the Canvas
and change the Layer to UI. The default is UI but make sure that it is still set to UI.
Default/Main Camera:
1.Select the Main Camera that was there already there and change the Clear Flags
to Skybox
.
2.Change the Culling Mask
to Everything
. Click on Everything
which is a setting of Culling Mask
and de-select/uncheck UI
.
3.Change Depth
to 0.
New Camera:
1.Create a new Camera
and name it UI Camera.
2.Select the UI Camera, change the Clear Flags
to Depth Only
.
3.Change the Culling Mask
to UI
.
4.Change Depth
to 1.
5.If the Canvas you want to display on top has the "Render Mode
" set to "World Space
" or "Screen Space - Camera
" then drag the UI Camera to the Canvas' Render Camera/Event Camera slot. You don't have to do this if the "Render Mode
" is set to "Screen Space - Overlay
".
That's it. This will always display the UI in the front. It should on default but its not working for you for some reason.

- 121,791
- 22
- 236
- 328
-
These steps broke everything in VR so I basically had to just abandon that branch and start over. Still, this is good info and a good answer; just beware in VR! – Yes Barry Aug 14 '19 at 00:37
-
I tried this again and it didn't "break everything" but in VR it is bizarre. My canvases move around as I look around with my HMD so if I look down my canvas moves up, if I look up my canvas moves down, if I look left, my canvas moves right, etc. But I can't actually point at the canvas with my laser pointer. My laser pointer thinks it's in its position as it would be from the main camera. Idk if I'm making sense... Hoping you could help! – Yes Barry Dec 26 '19 at 19:16
Thanks to @Programmer
ı understand the general logic but if you're working on a Virtual Reality , you have to do something more .
1-) Copy the Virtual Reality Camera and apply changes @Programmer
says

- 4,269
- 1
- 20
- 27

- 113
- 1
- 1
- 7
-
actually you just have to make sure the new camera is a child of the main camera or it copies its transforms – derHugo Oct 02 '18 at 11:52
-
@derHugo Ironically making the new camera a child of the main one in Oculus was the cause of my issues. – Yes Barry Jan 02 '20 at 19:20