Tilemap 2D: Tilemap.getTile always returns null

It doesn’t matter what I do but the tilemap.getTile function always seems to return Null, even though I clearly placed a tile on that position right before.

tilemap.SetTile(tilemap.WorldToCell(player.transform.position), highlight_tile);

Debug.Log(tilemap.GetTile(tilemap.WorldToCell(player.transform.position)));

I’ve also tried to manually draw tiles in the tilemap, but the function still returns Null

Not sure, but maybe the problem is that the z value of of player.transform.position is ignored when setting the tile, but not when trying to get it. What happens if you cast the player position into a Vector2 first or set the z to 0?

Vector2 playerPosition = (Vector2) player.transform.position

then use that to set and get the tile.

2 Likes

turns out you were right :), thanks a lot