Is it possibly to sort sprites along tilemap with top down sorting order?

Think top down view with front facing side visible, in style of JRPG games

So sprites can be sorted in this manner, using their pivot, sorting order or custom transparent sorting axis.

Tilemap Renderer can be set to sort top to bottom, or however you want to view it, this makes it possible to have tiles higher in Y sort behind those lower in Y-axis.

However, Sprites and Tilemap don’t seem to be communicating between each other…

I could change Sprite Sorting layer or Order in Layer, either for Sprite or for Tilemap, but it won’t allow Sprite to go in-between tiles. If each row of Tilemap somehow had different order in layer, this would be easy.

Any solution to this, other than start splitting tiles into go-behind and normal layers?

Edit:
I drew a picture. Something like this happens. Either sprites are in front of behind tiles fully. Sprites and tiles bot sort between themselves correctly, but there is disconnect between both. Dots are pivots, but this doesn’t seem to matter.

I literally made the same post in this thread yesterday:

It’s a limitation of the Tilemap system unfortunately. It seems the only way around it is to have 2 tilemaps for foreground tiles and background tiles. (Or create individual sprites/game objects for every single foreground tile, which can then be sorted with other sprites the usual way).

I did read in another thread somewhere that the Unity 2D team are looking into this long term.

1 Like

@RidgeWare

I haven’t found your thread… so I’ll read it. Anyway, if this is limitation and not user error, that’s pretty big oversight, as Tilemap is rarely used alone without interacting objects. Then it is just more manual work.

@RidgeWare

Just to let you know, it might or might not be usable for you. After couple of ideas, I came up with one hacky solution:

  1. Set tilemap tile Orientation to custom.

  2. Rotate tile along x axis slightly (some fraction of degree, or one degree doesn’t matter).

  3. Then assign z-buffer using shader, like Unlit/Texture to tilemap.

This way sprites will go behind top parts of “up” extruding tiles, as long as their plane don’t intersect with slanted tile.

Edit:
As you can see, tiles and sprites sort as intended… same goes for camera view, both ortho and perspective (of course with limitations) but anyone who is interested can test it. White sprite will sort with black sprite, and both sprites will be behind walls below, and in front of walls above.

@LiterallyJeff

thanks for the reply.

Actually the gif is using transparency sort axis for sprites, like I mentioned.

However, like I wrote, it doesn’t seem to help with sorting sprites in-between tiles. AFAIK It will only help with sorting of sprites, not sprites vs tiles like the case is here.

About the video; Is there some specific part that could help me? Not complaining but if there is some trick or obvious thing I’ve totally missed, I will check that part only.

That’s fine for sprites, but we’re talking about tilemap tiles, where that process doesn’t work properly.


@eses

I’ve since played around with an addtional tile map for foreground walls, and to be honest I can live with it for the time being. It’s more workload, but not a huge amount more. Also, I can make both wall tilemaps use the same layermask for raycasting purposes, so it makes little impact on the code.

Hopefully in a new release they’ll implement something for tilemaps that can sort with sprites both front & back.

Tilemap tiles are sprites, they just get batch rendered. Read the section under “Mode”, use Individual sorting.

Also apologies for not reading the OP more closely, I tend to post in a rush these days.

3 Likes

Thanks, that’s a great help. I could swear I tinkered with that option before, but obviously I hadn’t used it properly.

I’m not sure what the performance will be like compared to chunk rendering, but it’s certainly a quicker design/workflow than buildng a foreground tilemap with chunk rendering.

@LiterallyJeff

Hmmm… is this only available in 2018.3, I’m still in 2018.2 and only see Sort order, Culling bounds, Sorting layer and Mask interaction in Tilemap Renderer.

It’s quite possible. I only updated to 2018.3 a few days ago, and the option is sitting there right below Sort Order.

It could prove to be a godsend. I’ve fully tested it now on my wall tiles (on 1 tilemap) and the sprites are now sorting correctly whether in front or behind a tile.

1 Like

@RidgeWare

Thanks for the info.

Better late than never I guess. This kind of feature seems like a must for any game using tilemaps other than full side view or top down.

I’ll consider updating my Unity version.

1 Like

There’s always the option of using regular sprite prefabs using a prefab brush or manually placing them as children of the grid. Using prefabs you can even have objects larger than one tile sorting properly based on root pivot.

The benefits of batch rendering in a tilemap are great, but regular sprites will not tank your frames per second by any measure.