Canvas is not rendering on top
Asked Answered
C

2

7

I used a canvas and Unity UI elements as a HUD. I want HUD to be in front of everything but it's not.

hud

Crinkly answered 8/6, 2016 at 13:42 Comment(0)
B
13

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.

Bronchiectasis answered 8/6, 2016 at 14:16 Comment(2)
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!Asberry
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!Asberry
C
2

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

Crinkly answered 9/6, 2016 at 5:52 Comment(2)
actually you just have to make sure the new camera is a child of the main camera or it copies its transformsIsidore
@Isidore Ironically making the new camera a child of the main one in Oculus was the cause of my issues.Asberry

© 2022 - 2024 — McMap. All rights reserved.