Added some UI elements inside a canvas in world-space render mode. There is an issue with the occlusion of UI elements with respect to the laser pointer. The pointer here is made from a line renderer. Here are the things that have been tried and still the pointer does not properly occlude the canvas.
The source code is from Unity and is available here. There is no related script that requires modification. Seems like a setting or shader change might only be required here.
It is possible to write a custom shader to test for depth, but this would be a very expensive shader - and it looks like you want to use it on VR, and I would not recommend to use it like so.
Over-engineered solution and still not very cheap but cheaper solution would be to render UI onto a camera that renders into RenderTarget
and passes the input to the UI.
Few notes:
Camera.Render()
when UI is updated.EDIT: After edit its much simpler problem!
UI is rendered at RenderQueue = 3000
you probably have unlit material as a line-renderer which has RenderQueue = 2450
.
You need to create a material with RenderQueue >= 3000
for your line renderer
If you don't want to create new material, you can change it from code
// use this with caution! As this can affect other materials when run in editor!
meshRenderer.material.renderQueue = 3100;
EDIT 2: If you have URP installed you might need to change the default material to something from URP. Default material uses Legacy shader which causes issues with the Line Renderer and UI.