orthographic camera rendering order?

I am trying to render some quads using a mesh with a spritesheet as texture (the reason I use a mesh is that I'm basically drawing a ton of static stuff on the game map that have no behavior; in other contexts the same spritesheet is used with a SpriteRenderer, animation, etc).
The sprites on the sheet have transparent pixels, and the quads for the sprites overlap (the spritesheet has gear options for equipping the characters, so I would draw a head, the draw a helmet on top, etc).

I have an orthographic camera pointing down the Y axis.
The issue is that when I try to layer the sprites using a mesh, with e.g. a quad for head at Y = 10 and a quad for helmet at Y = 20 (or 200), the orthographic camera seems to ignore Y. I can see in scene view that the helmet quad is "above" the head quad with respect to the camera, and yet the camera renders the head over the helmet; the defining factor seems to be the order in the vertex/triangle/uv arrays of the mesh - whatever quads are added later to the arrays (i.e. are at higher indices), gets rendered on top, regardless of Y...
Why is that?

Unity draws things a few different ways, regardless of ortho vs perspective.

The default 3D Renderers draw stuff according to Z depth - distance from camera.

Sprites draw according to Sorting Layer and Sorting Depth (properties of the Sprite Renderer)

UI Canvas Renderers draw in linear sequence, as if you were pasting papers atop each other

When you mix and match you can get these issues. There are workarounds for all combinations. Google up mixing sprites with 3D objects, and mixing 3D objects with UIs.

Are you using multiple cameras?, if so check out the depth of your camera to draw above other, also if you're using orthographic projection be aware of camera pos z to be lower than object you want to render

1 Like