godot icon indicating copy to clipboard operation
godot copied to clipboard

Tilemap with ysort enabled doesn't work together with regular sprite and ysort as parent

Open Kezzo opened this issue 3 years ago • 7 comments

Godot version

v3.5.1.stable.mono.official [6fed1ffa3]

System information

macOS Monterey 12.5.1 (21G83)

Issue description

With a scene hierarchy like this where the TileMap has ysort enabled. image

The player-node's sprite does not correctly sort based on the y-position with the sprite from the TileMap. If the player is instead made a child of the TileMap the y-sorting works correctly. Having to make separate sprites a child of a TileMap heavily inconviences the setup of scene especially if multiple TileMaps are used and need to sort correctly with each and other regular Sprites.

Steps to reproduce

  1. Create the above hierarchy
  • YSort -- Sprite -- TileMap (with ysort enabled)
  1. Start game
  2. Move Sprite and observe it's not correctly sorting with the sprites of the TileMap

Minimal reproduction project

N/A

Kezzo avatar Nov 27 '22 16:11 Kezzo

You need to enable ysort in TileMap layers too.

KoBeWi avatar Nov 27 '22 17:11 KoBeWi

You need to enable ysort in TileMap layers too.

"TileMap layers"? Where can I find that? Tilemap itself has ysort enabled as I described above.

Kezzo avatar Nov 27 '22 17:11 Kezzo

Ah sorry, I didn't read the version. Layers are only in Godot 4.0.

KoBeWi avatar Nov 27 '22 18:11 KoBeWi

This remains a bug in 4 beta 7, at least in so far as scenes instantiated by the tilemap do not y-sort correctly with nodes unless those nodes are children of the tilemap. This is after turning y sort on everywhere it "should" be, including the root "World" node below, the tilemap, tilemap layer in question and the bush scene itself. (just covering all my bases)

Does not sort correctly:

World
 * Tilemap
   * @Bush1 <- Generated by tilemap Scene collection
 * Player
 * Objects
   * Bush

This makes it impossible to sort objects from two separate tilemaps together.

mrbaggins avatar Dec 09 '22 07:12 mrbaggins

Actually, it may be fixed in b7. My Minimum project works correctly. My main project has required me to set my z ordering very wrong to what I expected, but now also works correctly. After reviewing my z settings I think b7 has this fixed.

I've uploaded a minimum project in 4b7 to prove this is no longer a bug.

Tilemap Scene Bug.zip

The upside down logo is the "Normal" node, the top left and bottom right logo are on the tilemap, and instanced via the tilemap.

Potential note: I'm on gdscript, not mono.

mrbaggins avatar Dec 09 '22 09:12 mrbaggins

SOLVED: In my case, it wasn't a bug, it was just fixing the sprite pivot on my character scene.

BTW, I'm having some issues with y-sorting as well.

v4.0.2.stable.mono.official [7a0977ce2]

Maybe some code sample. I'm trying to figure out if the issue is on my configuration or if it is really some bug. Anyway, here is the PR:

https://github.com/rluders/godot-simple-rpg/pull/15

In the project is possible to observe two separate usage:

  • 1st - I'm using the scenes as tiles
  • 2nd - I'm using the tilemap + scenes grouped by nodes2d

rluders avatar Apr 29 '23 20:04 rluders

My scene tree currently looks like

* World
** Areas
*** Forest
**** TileMap
***** SceneCollection Sources
*** [More Areas]

** Player

The TileMap Layers are:

  • Ground (Z-Index: 0, No Y-Sort)
  • Breakables (Z-Index: 1, Y-Sort enabled)
  • Environment Bottom (Z-Index: 0, No Y-Sort)
  • Environment Middle (Z-Index: 1, Y-Sort enabled)
  • Environment Top (Z-Index: 2, Y-Sort enabled)

The TileMap has Y-Sort enabled as well.

Y-Sort between Scene Collection Sources and normal Tiles seems to work. But the Player, Y-Sort enabled or not, doesn't sort into the TileMap nor the Scene Collection Sources.

Edit: I'm working around this right now by reparenting the Player to the current Area's TileMap. That first caused some hiccups because I have body_entered triggers to adjust the camera on Area enter and that triggered "twice" (read: infinitely) now. Checking whether the last entered area is the current area and stopping the trigger fixed that. I'm explaining that just to add some use-case context to the problem :)

dweipert-3138720606 avatar Apr 22 '24 12:04 dweipert-3138720606