How to enable autotiling, when I use set_cell during the game?

Godot Version



I’m creating an in-game level editor and want to give the player the ability to draw levels using a tilemap, that automatically connects. I have already set autotiling and I have already found a function set_cells_terrain_connect(), but I have no idea how to use it for my purposes, because for placing tiles I use function set_cell(), that requires tiles ID (may be I should use another function, I really have no idea now(…)

Thanks in advance!

You need to use the TileMap.set_cells_terrain_connect() function if you want them to auto-tile. TileMap.set_cell() won’t auto-tile.

So… Sorry for the misunderstanding, but where then can I give this function a position to place the tile? Using set_cell() allows me to set the coordinates for the new tile in the second argument, which in my code is get_global_mouse_position(), but I don’t see such an argument in the set_cells_terrain_connect() function.

2nd parameter is an array of Vector2i, this is your positions.

Thank you very much! I understood my problem. I thought the second parameter should be an array of tile coordinates that I want to use from my tile map. if someone in the future will be interested, it is just:

var cell_position : Array[Vector2i] = [Vector2i(0,0)]

func _process(delta):
	if Input.is_action_pressed("mb_left"):
			cell_position[0] = tile_map.local_to_map(get_global_mouse_position())
			tile_map.set_cells_terrain_connect(0, cell_position, 0, 0)
1 Like