How can I fix sorting issues with multi-page atlases?

In my current project, I’m attempting to optimize a sprite atlas that’s become a bit large (8192x8192), so I decided to split the atlas into two separate pages (4096x4096 x 2), but this introduces sprite “popping”, where sprites that are on the same sorting layer, but are in different pages of the same atlas, are fighting each other for sorting, making two sprites appear to pop from behind each other when the camera moves (perspective camera). Is there a way to solve this, other than keep the larger atlas?

You probably just need to explicitly set the SpriteRenderer’s sorting order / layer.

NOTE: just because it works in 8192x doesn’t mean it will always work, if you have ambiguous ordering.

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 (along with different Layers and LayerMasks drawn to different-depth 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.

There’s lots of third party open source packages available as well, such as this:

Kurt…

Are you on Unity’s payroll yet? Seriously, I’d ask for a paycheck at this point :wink:

OK, some clarification here without having read any of your links just yet -

I’m using a Grid/Tilemap setup for all my background/foreground environment sprites. Each tilemap is a separate sorting layer, and each tilemap has a different Z-depth from the camera. For example, the first tilemap has a Z-depth (if I understand this correctly… Transform.position.z?) of 0, and a background sorting layer of 0. Then, as we go further back in the background, the next tilemap has a sorting layer of -10 (for example), and a Z-depth of 1, and so on and so forth. There’s about 12 tilemaps total for this specific area, all with their own sorting layer/Z-depth values. All background/foreground sprites in this area are in this one, large atlas. I’m currently using 2D-URP. The camera is at -10 on the Z.

I can certainly add Sorting Group components to each tilemap, but, and again, I haven’t read your links yet, wouldn’t this be the same as just setting the tilemap sorting layer in the tilemap renderer itself? My understanding of sorting groups was that it has the benefit of adding sorting layers to game objects that otherwise don’t have a component that allows layer sorting. Maybe sorting groups work completely differently from sorting layers, so I’ll read more about that in the DOC’s just to see if I can get some different results…