Render real world UI infront of only 1 other Layer

Hello, I was wondering if there was a way to render a real world UI item in front of only one other single layer. I know you can render it in front of everything using multiple cameras, or by a custom shader ignoring z. I have a health bar that I want to stay behind everything, but my character which is on a separate layer. I imagine it would be making a custom shader but I’m not very familiar with them. Any help would be great thanks!

Hello,

this can be solved in various ways, possibly the easiest is to set the Canvas Render mode to World space. This way your UI will be actually part of the 3D environment, so objects can cover it from view. You will also need a script that anchors the UI to the position of the player and moves it slightly towards the camera (for example by -camera.transform.forward).

Another solution is to use multiple cameras and layers, and render the background first, then the player and the UI, and finally the environment that can cover it, using Depth only for the culling mask and higher Depth value for each “layer” drawn.