TileMap force_update removes layer

Godot Version



I am attempting to set_custom_data for every tile a building touches on my tilemap. when I call force_update(0) in my runtime update func, it removes the layer completely. I am simplying modulating the tiles for debug purposes, the goal is to create a dictionary of tiles with the has_building custom data


func create_warren(location : Vector2):
    var local_pos = tile_map.local_to_map(location)
    var tileset_source_id = 6
    var atlas_coords = Vector2i(0, 0)
    var buildings_layer = 5
  # add building to tilemap
    tile_map.set_cell(buildings_layer, local_pos, tileset_source_id, atlas_coords)
    var ground_layer = 0
    var tile_data : TileData = tile_map.get_cell_tile_data(ground_layer, local_pos)

    # set has_building for every tile the building touches
    var i = -5
    while i < 5:
        var l = local_pos
        l.x += i
        var next_tile_data : TileData = tile_map.get_cell_tile_data(ground_layer, l)
        if next_tile_data:
            # trigger TileMap._tile_data_runtime_update
            next_tile_data.set_custom_data(tile_has_building, true)
        i += 1


extends TileMap

var modulated_cells : Dictionary

func add_modulated_cell(v : Vector2i):
    modulated_cells[v] = Color.DARK_RED

func _ready():
func _use_tile_data_runtime_update(layer, coords):
    var r = modulated_cells.has(coords)
    return r

func _tile_data_runtime_update(layer, coords, tile_data):
    if layer == 1:
        var color = modulated_cells.get(coords)
        tile_data.modulate = color
        force_update(0) # removes my layer 0 while also modulating somehow
        print_debug(str(tile_data.get_custom_data("has_building"))) # returns false somehow

after I call force_update my layer index 0 is removed completely revealing the tileset layers below.