Advanced Z-ordering hell

Hi all. I’ve been working on an isometric sprite based game. I’m new to Unity, but not to programming or game development in general. Right now I’m having 2 issues regarding my layering that I can’t seem to solve. I’ve scoured all over the internet to no avail, so I’m hoping for some bright ideas from this forum.

Layer setup
Since it’s an isometric game with multiple height levels, I’m using a Z-as-Y tilemap. Together with a custom sort axis of (0, 1, -0.13), it will correctly sort characters and the map tiles based on position. Characters can be in front of the walls, behind the walls, or on top of the walls, depending on their Y and Z position.
8175242--1064267--upload_2022-6-2_10-8-23.png
image 1: my isometric z-as-y ordering setup

This works great, and only works because the characters and tilemap are on the same layer and order.

The problems arrived when I started adding stuff.

Problem 1
The biggest issue I haven’t been able to solve, is how to display a silhouette of my characters when they are behind the walls. This is the kind of tech I’m looking to create:
8175242--1064285--upload_2022-6-2_10-21-36.png
image 2: my current silhouette solution behind a wall. Looks ok!

Putting a mask on the tilemap is not a solution, because it would also cause the silhouette to show up when the character is in front of that wall (like the head could clip into the mask area). Following some suggestion from another post, I added a child sprite to the character that follows the same animation, but has transparency and a higher layer. The problem I’m having with this solution, is that the silhouette now shows up whenever the character is behind anything, even another character. This looks weird, and is not what I want. I only want it to show up behind my tilemap, and possibly other objects which I can specify.

8175242--1064291--upload_2022-6-2_10-27-5.png
image 3: my current silhouette solution behind another character. Looks weird…

Problem 2
Tiles can be selected. Both for selecting the actual tile, and for displaying possible movement. Sometimes these selections can be on tiles that are not visible to the player, such as behind a wall. Since I still want these “selected tiles behind walls” to be visible, the tile selector is on a higher layer. Problem with this is, it now also overlaps everything else, such as characters. I half solved this by adding a Sprite Mask to the characters, and have the selector set to “Visible Outside Mask”. Problem is, you can’t set a material for Sprite Masks. My characters can have an outline when they are selected, which is rendered through a shader material. This outline is not masked. I want the outline in front of the selector too.

Ideally, I’d get rid of the Masking solution altogether. It feels like a hack. Is there a better way to do this, or at least a way I can get my outline to show up above the selector?

8175242--1064276--upload_2022-6-2_10-15-26.png
image 4: my current tile selection solution.

This is what it looks like now. I want the blue outline over the selector as well, just like the character.

I’m not afraid of getting my hands dirty with shaders, render textures, or anything you might throw at me. Just know that I’ve already looked at these directions for solutions, so please be specific if you have an idea. Thank you!

8175242--1064291--upload_2022-6-2_10-27-5.png

Perhaps this can give you some more ideas:

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

https://discussions.unity.com/t/841904/2

In short,

  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.

Additional reading in the official docs:

https://docs.unity3d.com/Manual/2DSorting.html

Hi, thanks for your reply. I’m familiar with how these draw methods work. I’m using URP 2D renderer, and have it configured to sort by Y-axis and a small bias to Z. This is what the documentation recommends for 2d isometric.

I thought this video gave me a solid lead:

But it turns out this technique only works for 3d. Firstly, the 2d URP doesn’t have the function to filter layer masks. Secondly, the 3d URP with these settings doesn’t seem to work for Sprite renderer (I’ve tried).

Yet, I refuse to believe that what I’m trying to do is impossible with Unity.