Sprites with different Z positions still gets mixed up while rendering game

,

Hello,
Because of my generation setup, I’m trying to avoid Sorting Layer option and I keep everything on Default Layer with no Sorting Layer.

I want to rely on the Z position of my sprites to render them properly, I read that a camera with perspective mode would do that. But for some reason it’s not working, my sprites are close, yes, but they are not on the same Z position so why would they render on randomly/glitchy way ?

I really don’t want to use Sorting Layer if I don’t have to,

Any suggestion would be greatly appreciated :slight_smile:

Three (3) primary ways that Unity draws / stacks / sorts / layers / overlays stuff:

In short, as far as the Standard Rendering Pipeline,

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

  2. SpriteRenderers draw according to their Sorting Layer and Sorting Depth properties

  3. UI Canvas Renderers draw in linear transform sequence, like a stack of papers

If you find that you need to mix and match items using these different ways of rendering, and have them appear in ways they are not initially designed for, you need to:

  • identify what you are using
  • search online for the combination of things you are doing and how to to achieve what you want.

There may be more than one solution to try.

For instance, you may even use multiple co-located cameras to more-explicitly control apparent draw ordering.

Additional reading in the official docs:

And SortingGroups can also be extremely helpful in certain circumstances:

Other rendering pipelines may have other ways of layering (HDRP and URP). Go see the latest docs for details.

Hey Kurt, thanks for jumping in !

I’m using URP (well 2D Renderer) but I just don’t understand how people can manage to work with Sorting Layers settings in a large perspective scene.

Each time you need to place a new sprite, or even worst, moving one of them in the Z axis it’s IMPOSSIBLE to see what you’re doing !

I mean let’s say I have this Leaf that I want to move before the Tree, I can’t see what I’m doing if I don’t change the Sorting Layer before moving it, if not, no matter what I do with my Lead transform, I can’t see it placed where I want.

It seems crazy to me xD

I’m working on a script to update the Sorting Layer of the transform that I’m moving in realtime but it seems overly complicated for such a usual task !

I agree with you sorting layer is completely unusable

what you need to use is transparency sort axis and set it for z (0,0,1) or (0,0,-1)

you can find it depending on your render pipeline its located in different places, most likely you should find it when you inspect your renderer asset

make sure all your sprites are on the same sort order(default 0) and all on the same mask layer

1 Like

THANK YOU SO MUCH !

It was driving me crazy…
I’ve setup an editor scripts that resolves Z axis competition, with this settings you gave me I think I might be able to render this bloody scene correctly :wink:

1 Like

Hey bro ! @karderos
The Z sorting is pretty cool with this new setup but how do you work with 2D Lights then, it requires sorting layers to be set isn’t it ?

3D lights won’t work with the 2D Renderer ^^’

What is the trick ? :smile:

Thanks again mate

no sorting available for 2d lights, sadly

That’s what I was afraid of…
This is crazy !

2023, not solution to create a nice 2d game in a 3d environment xD

I guess I shouldn’t be using the 2D Renderer at all ? Would URP be a better choice so I can use actual 3D lights ? But then the Sprites wouldn’t be lit, right ? -_-

not sure if 3d lights will solve it hmm well

what I can show you is this article
https://www.gamedeveloper.com/programming/graveyard-keeper-how-the-graphics-effects-are-made

but myself I wouldnt dream to try this because I am not a pro coder

1 Like

Very nice read !
More suitable for 2.5D though (and they don’t seem to be relying on 2D Renderer… )

I curse the day I fell for this new renderer, should have shot me in the foot instead xD
Everything is just more complicated

  • shader blur ? → forget about it
  • parallaxe and lighting ? → same

Jeeeeez

I made the same mistake of using the new 2D renderer. I’m in the process of converting my project back to 3d urp. As a standard rule. Don’t use any asset published by unity since ~2019… Everything is half complete garbage that doesn’t work.

1 Like