Sorting Layers of Sprite Renderers not working on Vision Pro

I have multiple game objects with a sprite renderer but some are showing in front of the others.

The ones in the back are furthest out on the z axis than the ones in the front. I also put the ones in the back on the Default sorting layer while the front objects are on the GameUI sorting layer.

It still sometimes shows the sprite renderers that are in the back, in front of the ones in the front.

Are there any other solutions that I am missing?

(I have an unbounded scene using AR on the Vision Pro)

(This is assuming that you’re using RealityKit mode.)

By default, all SpriteRenderers are put into a single sort group and given an order that depends on their Unity sorting layer/order. At least at the moment, that means that their depth isn’t considered when sorting them. You can override the sorting by using an explicit VisionOSSortingGroup, but I’m not sure that will address your issue.

Let’s say you have sprites A, B, and C at respective Z positions 0, 1, and 2. Is the issue that they sort correctly when looking in one direction (say, Z+) but not when looking in the opposite direction (Z-)–that is, is the issue that they are not depth-sorted?

If so, the only workarounds at present would be:

  • Use MeshRenderers rather than SpriteRenderers (since those are not automatically added to a sorting group, and will thus be depth-sorted if transparent).
  • If the sprites don’t need to be transparent (i.e., alpha clipping will suffice), you could use a shader graph with alpha clipping rather then blending and add them to an explicit VisionOSSortingGroup with Depth Pass = Pre Pass or Unseparated, which will draw them in whatever (fixed) order you choose but use depth testing to ensure that nearer pixels obscure farther ones.
  • Since you’re using unbounded mode, you could get the view position and set the sort orders of the sprites explicitly based on their computed depth.

We could also, for example, add a mode where we don’t automatically add sprites to a sorting group (which would mean that they’re sorted by depth, but that they ignore the Unity sorting layer/order). If you’re interested in such a mode, I’d suggest submitting it to our road map.