I’m working on a 2d isometric tactics game, and am currently implementing tile indicators for things like movement and abilities, etc. But, I’m having some issues with getting the instantiated indicator objects to appear behind tiles on higher Z layers, and can’t seem to work out the best way to tackle it.
As you can see, the tile indicators are visible through the tall block of brown tiles on the right, when these should be obscured from view. I have a character set up with grid-based movement as well, however, it’s the same for the character sprite as well.
I shall post my details in a following comment with more attachments with my set up, but if anybody could provide any insight, that would be great.
(For context, I first get the Cell Position of my tile and use that to get the World Position. I then instantiate the tile indicator at the tile’s World Position, and then set the SpriteRenderer.sortingOrder to be the Z value of the tile + 1, to make it visible on top the one it’s on).
Each of the tiles have their pivot set to the Bottom Center, with my tile indicator sprite pivot set to the Center.
Does anyone have any ideas of what I could have missed in my set up that is causing this to not work?
If you are using sorting axis then more or less you can’t use sorting layers and order in layer. Those have higher priority than sorting axis so you will have to use different approach to ensure correct order.
If you look at unity docs for sorting order Unity - Manual: 2D Sorting then the things that have weaker priority than distance to camera(sorting axis) are: sorting group, material/shader, tiebreaker and of course the sorting axis themselves.
sorting group → Very useful in slightly different situations in combination with sorting axis but I don’t think it helps in this situation with tilemaps. Without tilemaps you could make each tile their own sorting group and then parent the red indicators to the tile. That’s not practical for tilemaps.
tiebreaker → useless because as Unity docs state you have no control over it
material/shader → haven’t tried this myself but it might be possible to achieve desired result by changing render queue value in the material properties. It is also possible that I am compeletely wrong about this.
slightly tweak the position of indicators ~1 pixel should be enough, so that they are slightly higher than corresponding tiles, but in general more or less the same relative to other tiles. You might have to adjust sprites to ensure that they are visually still in the same place.
Hey, thanks for replying and for the additional info!
I tried your last suggestion (adjusting the position of the indicators slightly), though it didn’t make a difference.
Here it is in orthographic view:
And perspective view:
So if I understood what you meant correctly, adjusting the position (at least the Y pos) wouldn’t make a difference, unfortunately because of the distance in Z.
For additional context, I’m just using a single Tilemap for the core tiles and then adjusting the Z position for elevated tiles (in increments of 2)
i dont know much about isometric sorting but how that is working seems odd, I feel like the z position of the higher tile should decrease so it is closer to the camera instead of going farther. It might seem like it makes sense that higher z = more height but it seems like it doesnt make sense for the sorting
It doesn’t really matter as long everything is consistent. You can configure sorting axis in either direction, whatever makes things more convenient for the game objects.
I just got it working! So it turns out, the sorting order doesn’t matter at all (probably because of what you said before), but the transform’s Z position had to be even greater than what I was originally off-setting it.
I was previously just taking the tilemap’s tile Z pos, and then setting the tile indicator’s Z pos to be that + 1, which wasn’t working, but by doing that + 3 instead, it now works!