How can I identify individual tiles in a TileSet?

Godot Version

Godot 4.6.1-stable

Question

I recently upgraded from version 3.6.2 to 4.6.1, and I’m having trouble understanding how to work with TileMapLayer. How can I retrieve and specify the indices or names of tiles in a TileSet? I remember that in the previous version (3.6.2), it was quite straightforward: there were tiles with their names in the corner, and I could use these names to set the tiles in the TileMap’s tile grid when generating the map.
However, I can’t find anything similar here.

For example, I need to arrange the base tiles in the TileMapLayer based on their name or index

1 Like

I would use terrains, that way you can set certain tile types and check for them and whatnot, as for specific tiles, thats kinda a tough thing, it depends on what you want to do, if its to position an object at a specific place then you should use the position.x or position.y, otherwise i am not entirely sure how to take the index of a specific tile in a tilemap layer. . .

The most suitable thing I’ve found for myself is TileData, which represents a single tile in the TileSet. You could say that this is the tile’s identifier, but then you need to store them somewhere when adding new tiles.
For example, you can check if a specific tile is present in a given cell:

if str(get_cell_tile_data(Vector2i(0, 0))) == "<TileData#31708939719>":
	print("True")
else:
	print("False")

But I’m not sure if this is an optimized check.

In general, as I understand it, tiles in a TileSet are identified not by a specific number, but by a set of values: the source, the coordinates of the atlas, and the alternative tile. There is also TileData, but I find it inconvenient to work with it because it is not displayed in the inspector and can only be printed to the console. Essentially, if you need to identify tiles within a single TileSet, you can use the coordinates in the atlas and store them for each tile as a vector2i()

Example:

var tiles_data = {
    'empty': Vector2i(0, 0),
	'green': Vector2i(1, 0),
	'blue': Vector2i(0, 1)
}
1 Like