Sprite incorrectly ysorts over tiles

Godot Version

4.4.1

Question

i’m trying to add y-sorting to my game that uses tile map layers, but it isn’t rendering over the player sprite correctly. if i set the player’s z index to 0 then the head shows underneath the tile where i don’t want it to


if i set the z index to 1 then it actually works correctly, but then it makes the y-sorting not actually function (the player just renders over everything)


is there any way to actually fix this, ive been trying for a while :broken-heart:

What does the structure of your scene look like?

With Y-sorting enabled on a parent node (‘A’) but disabled on a child node (‘B’), the child node (‘B’) is sorted but its children (‘C1’, ‘C2’, etc.) render together on the same Y position as the child node (‘B’). This allows you to organize the render order of a scene without changing the scene tree.

I believe your Player needs to be a sibling to the TileMapLayer nodes.


I would refer to this answer: Is it possible to y-sort tilemap scene collection tiles? - #2 by salianifo

you shouldn’t change the z-index, y-sorting only works on nodes with the same z-index. Also, you will need to set y-sort enabled on the tilemaplayer, and on any parent nodes the tilemaplayer and player have before their first shared parent. Don’t set y-sort enabled on the player though.

Also, y-sorting is based off the y-sort origin of the tile in the tileset, so you might need to adjust that since it’s set to the middle by default. for the player, the y-sort origin is just the position.