How to replace "update_bitmask_region()" for Godot 4.0

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By PE4

Hello, i wanted to convert my project 3.5.2 to 4.0.2 but many things changed and i resolve many problem but there are some problems that i can’t solve like this one:

I had a script for procedural generation (the script at the bottom), the problem is for convert the function update_bitmask_region() its not work (Invalid Call. Nonexistent function ‘update_bitmask_region’ in base ‘TileMap’.

I have already tried replacing this function many times but it never worked.

(the script is from the tutorial from HeartBeast)

extends Node2D

const Player = preload(“res://Entity/Character/Player.tscn”)

var borders = Rect2(1, 1, 4048, 4048)
@onready var tileMap = $TileMap

func _ready():

func generate_level():
var walker =, 11), borders)
var map = walker.walk(200)

var player = Player.instantiate()
player.position = map.front()*32

for location in map:
	tileMap.set_cell(0, location, -1)
tileMap.update_bitmask_region(borders.position, borders.end)

func reload_level():

func _input(event):
if event.is_action_pressed(“ui_accept”):

:bust_in_silhouette: Reply From: FH


For your code you’ll need to use set_cells_terrain_connect() instead of update_bitmask_region, you can find the docs here.

Your code would look like this instead:

var player = Player.instantiate()
player.position = map.front()*32


var cells = []
for location in map:
tileMap.set_cells_terrain_connect(0, cells, 0, 0)

I’ll walk you through the parameters: set_cells_terrain_connect(LAYER, ARRAY, TERRAIN)

  • LAYER = The index of the layer you want to use to place your tiles on

  • ARRAY = This is an array of your tiles, I created an array call cells and that holds the locations of the tiles you want to place

  • TERRAIN = The index of the terrain layer you want to use, you may have more than one so pick accordingly