Best practice for stacking TileMapLayer nodes with YSort in Godot 4.4?

Godot Version

4.4

Question

Hello everyone,

I’m working with Godot 4.4 and trying to figure out the best practice for creating vertical structures with TileMapLayer that also sort correctly with a player character using YSort.

I understand that in recent versions, TileMap has been deprecated, and using multiple TileMapLayer nodes is now the recommended approach.

My scene setup is as follows: I have a parent 2D node, and its children are the Player and several TileMapLayer nodes (e.g., wall1, wall2).

My goal is to have wall2 render on top of wall1 to create a taller wall, while also having the Player sort correctly behind this combined wall structure.

Here is the issue I’m facing:

  1. If I enable YSort on the Player and both TileMapLayer nodes, the layers do not stack correctly. They are all sorted individually against the player’s Y-coordinate.

  2. If I disable YSort on the TileMapLayer nodes, they stack correctly on top of each other, but then the Player no longer sorts behind them.

So, my question is: what is the correct workflow in Godot 4.4 for stacking TileMapLayer nodes vertically while ensuring they work as a single unit with a parent YSort node?

I feel like I’m missing a key concept about how YSort interacts with multiple TileMapLayer nodes. Any guidance on the best practice for this would be greatly appreciated.

Thank you!

You should alter the y-sort origin on the TileMapLayer that should be one level up. Set it to whatever the height of the wall is. It will then offset the y-sort for the tiles within that layer by that value and give you the effect you’re looking for.