I am making a painting game, where you place pixels on a tilemap as paint, and i need to check if one tilemap is equal to another, i mean if the two tilemaps contain the same cells. I tried using if tilemap_to_paint.tile_map_data == tilemap_main.tile_map_data: but after painting it wont work
Thx!
Thats a good try actually but using tile_map_data == tile_map_data won’t work as expected because tile_map_data is a reference type (TileMapData), and you’re just checking if both variables point to the same object — not whether the actual contents (tiles) are the same.
To compare two TileMap contents (cell by cell), you’ll need to manually iterate over the used cells and check for matches.
Maybe something like this? Obviously integrate it with your own code.
func are_tilemaps_equal(tilemap1: TileMap, tilemap2: TileMap) -> bool:
var cells1 = tilemap1.get_used_cells()
var cells2 = tilemap2.get_used_cells()
// First check if they cover the same cells
if cells1 != cells2:
return false
// Then compare the tile IDs in each cell
for cell in cells1:
if tilemap1.get_cell_source_id(cell) != tilemap2.get_cell_source_id(cell):
return false
if tilemap1.get_cell_atlas_coords(cell) != tilemap2.get_cell_atlas_coords(cell):
return false
return true
what you are trying to accomplish is not an easy task, trust me - I just finished a year long journey using it. The best I can recommend is to read the docs TileMap — Godot Engine (stable) documentation in English so that you understand how the TileMap node works and which methods are available so that by mixing the ones you need you can accomplish all the features you are envisioning.
and be careful because there was a major update with the TileMap during the version 4 .. I don’t quite remember the exact one though. But I had to make a great deal of changes to migrate.