Tile Map: How to change one tile's sorting order or z-axis?

I need individual tiles on certain tile maps to calculate their sorting order or z-axis relative to objects around it.

For example, I have a ROAD SIGN. The player can walk behind it like this:

[PLAYER]
[SIGN]

Now the sign is in front of the player.

Or the player can stand in front of it like this:

[SIGN]
[PLAYER]

Now the player is in front of the SAME tile.

How can I achieve this?

And it gets more complicated when I consider that other GameObjects (for example, animals or random human characters) also need to be able to move in front and behind one tile.

RPG Maker has this standard but I don’t know how to achieve it in Unity…

Use layers.

No, you misunderstand the question.

I need the layers of an individual tile to change dynamically. Not an entire tilemap.

4 Likes

A Tilemap in Unity is like a Layer in Tiled.
You can change the layer of an individual tile by moving it from one layer to another.
If you have a Back layer and Fore layer you can put grass etc on Back and signs etc on Fore.
At least that is how i did it… maybe a better way good luck :slight_smile:

If I need each barrel and chest to have their sorting order changed dynamically I will need to make 500+ tilemaps for one scene hehe

idk, you can paint normal prefabs and objects into tilemap too

You used to be able to change the rendering type to individual, I.e each tile was a single mesh and you could change sorting order from z to y in project settings. However this option seems to no longer be available. I would like to know the expected workflow to get this sorted as well:

https://discussions.unity.com/t/648177

Generally you use tiles because it’s more performant than GameObjects in the case of rendering a tile, I am sure we have all written our custom brushes.

could anyone provide a more concrete example though?
why would it not be enough to put a sign or a barrel or a chest on a foreground layer?
it what actual situation would each barrel need it’s own layer?

No-one is saying or even wants to put each barrel on their own layer, it’s about painting certain tile objects and rendering them based on their y value. This allows your character to dynamically change their order based on y and walk up to say, fences, barrels or trees from the top and bottom and render in the correct order. Hell you could chunk purely on the x axis and render them on the y and it would work out the same.

1 Like

ActualCrazyAtlanticblackgoby

I’m interested in seeing your workflow rather than just the end result.

Yeah, a very slow workflow. It becomes tedious without a lot of brush scripting(To auto add parts of tiles to specific layers).

Is there any consensus for getting around this major limitation of tilemaps in Unity? I’m currently making a game with large dungeons with a vertical depth effect, so I have endless foreground walls and background walls to manage.

Would the best option be to simply have an extra tilemap for foreground walls? I already have 2 separate tilemaps for walls/ground, so one more tilemap for south-facing walls wouldn’t be much more work. They nicely overlap so drawing the tiles would be easy.

I think I prefer that to creating hundreds and hundreds of individual objects for every tile in the foreground walls.

Such a shame this major problem was overlooked when it was implemented.

My plan is to position the sprites in a way that these taller ones are 2 tiles high. Then you put the normal collision on the bottom half and put the top half on the foreground. Just be sure the height of your character vs. the position of the collider prevents their head from reaching the top half when standing in front of it.

Just to confirm, Unity 2018.3 solved this issue for me completely with the new Render Mode setting in the TileMap Renderer. By rendering tiles individually, they now sort correctly with every sprite that moves in front or behind.

So there’s no more need for 2 separate tilemaps for foreground and background wall tiles.

6 Likes

I must be doing something wrong. I’ve messed with every setting I can find, but my player is always appearing in front of my tiles. Is there some tutorial or helpful article (the Unity docs aren’t much help)?

I suggest perhaps posting some screenshots of your inspector windows for both your sprite and the tilemap.

Individual tiles rendering works, as long as you don’t have a fence-like object that is more than a tile high, in which case you will need my solution here:

easier solution is to adjust the sorting axis:

4 Likes