TileMapLayer get_cell_atlas_coords returning (-1, -1) every time

Godot Version

4.3

Question

I’ve been trying to implement a system in my game that checks the tile that the player is standing on. I won’t go into specifics, but I noticed that the get_cell_atlas_coords function doesn’t seem to be working, as it returns (-1, -1) every time I try to use it. This is my code:

print((get_node("start") as TileMapLayer).get_cell_atlas_coords(Vector2i(5, 20)))

This is a minimal example of what I’m trying to do. The TileMapLayer is named “start“, but won’t return the atlas coords of the tile. I’m sure the atlas is set up correctly, and that the tile exists. Why won’t it work?

The layer is clearly convinced there isn’t a tile at the coords specified. There are few things here that could cause that - either the cords are wrong, or the layer is wrong, or there is a bug. Not much the forum can do in either of those cases :thinking:

Hey, thanks for the reply. Something I forgot to mention, and I don’t know if this is important, but would scaling up the tile map cause anything like this?

No, because the tile map coordinates work independently from world coordinates (e.g. Vector2(0, 0) in the world != Vector2i(0, 0) on the tile map)

Have you tried multiple different coordinates, not just (5, 20)?
I don’t think it’s possible to reproduce the error without more information, could you maybe share a minimal reproducible project or the scene file?

You could try to print TileMapLayer.get_used_cells(), just to double check which cells contain tiles and if (5, 20) is among them.

2 Likes

Thanks, I’ll try that