World space canvas in VR, how to get proper sorting order?

Hi, I’m creating a VR game and having trouble sorting UI to show up in the correct order based on distance to the camera. My canvases are in world space, but often the one that is further away is rendered on top of the closer UI. I tried the sort order but that forces the sorting, so if the player moves around to the other side it will be forced to the incorrect order as well. On objects inside of one canvas, they only sort based on their hierarchy so that doesn’t work either (ie: enemy health bars, they can’t be on the same canvas I guess because then the order is completely based on the hierarchy, so do we need a separate canvas for each health bar?)

Also, transparent objects (standard shader) and particles will sometimes show up rendered over the ui even if they are actually behind it from the perspective of the camera.

Any best practices to how to deal with UI sorting in VR or I guess world space canvases in general?

Bump, anyone have any experience with UI sorting?

Bumping this. I’m having the same issue with sorting canvases in world space for a VR project, and there doesn’t appear to be an obvious solution.

I still haven’t figured it out, no idea really how to get ui to have proper depth with VR. Only thing i can think of is to have each ui element be it’s own canvas but even then the depth sorting isn’t always correct, so we may just fall back on using some quads and text meshes instead of the ui system.

Yes each item would need to be on its own canvas. A canvas is considered one renderable mesh. Thus its would act like any other object and sorts based on its bounding box.

“Each ui element be it’s own canvas but even then the depth sorting isn’t always correct”

My guess would be because the bounds of the canvas were too large and it was sorting based on the middle of the object.

Ok thanks for letting us know. Is there a big performance hit by using more canvases in VR? ie: if I have an RTS game with say 30 units on screen with each one having it’s own canvas for it’s health bar + stats.

Also, what is the best way to deal with sorting between UI and transparent objects like particles and the transparent Standard shader? for example I often get the UI showing up in front of the partially transparent objects even though the UI’s origin is further away from the camera.

Hi @phil-Unity ,

I am encountering this issue with a pretty minimal setup.

I have 2 world space canvases. They are each pretty small, and they are next to each other but have a decent amount of distance between them. Each canvas is nothing more then a single image.

I find that, depending on the angle of my view, the z sort doesn’t work correctly between the 2 canvases.

Is there a z buffer clear between each of the canvas renders? And if so, is there a way to disable / prevent this in my scenario? Or if that just wouldn’t help; is there something else I can be doing to fix this issue?

Thanks

1 Like