Tilemap updating issue (bug?)

Godot Version

4.2.2

Question

Hi!

I continue to create in game level editor. So I’m using the set_cells_terrain_connect() function to set the tiles, but I can’t imagine what I need to remove the tiles. The erase_cell() function actually does what it’s supposed to do, but the tiles around it aren’t updating.

Thanks in advance!

image

After using erase_cell, call set_cells_terrain_connect on the tile next to the one that was erased and just set it to what terrain it is already. Make sure to pass the last argument ignore_empty_terrains as false so it takes the empty cell into account.

1 Like

Thanks for the answer, but I encountered another problem.
If I erase a cell surrounded by four tiles, everything works fine.
But if I delete a cell surrounded by two tiles, the tiles on the top and left won’t update.

cell_position[0] = tile_map.local_to_map(get_global_mouse_position())
if Input.is_action_pressed("mb_right"):
	var surrounding_cells = tile_map.get_surrounding_cells(cell_position[0])		
	tile_map.erase_cell(0, cell_position[0])
	for cell in 4:
		if tile_map.get_cell_source_id(0, surrounding_cells[cell]) != -1:
			cell_position[0] = surrounding_cells[cell]
			tile_map.set_cells_terrain_connect(0, cell_position, 0, 0, false)

Maybe I am not using set_cells_terrain_connect() in a right way?

maybe it’s bug??? i tried your code and i can’t get it to work either

I have solved the problem!!

All you need, is just add erase_cell() function before you use set_cells_terrain_connect()

Like this:

cell_position[0] = tile_map.local_to_map(get_global_mouse_position())

if Input.is_action_pressed("mb_right"):
	var surrounding_cells = tile_map.get_surrounding_cells(cell_position[0])		
	tile_map.erase_cell(0, cell_position[0])
	for cell in 4:
		if tile_map.get_cell_source_id(0, surrounding_cells[cell]) != -1:
			cell_position[0] = surrounding_cells[cell]
			tile_map.erase_cell(0, surrounding_cells[cell])
			tile_map.set_cells_terrain_connect(0, cell_position, 0, 0, false)

And it works great then:

shatteredreality, thank you for your help!

1 Like