Can't get the _tile_data_runtime_update() function to work

Godot Version

4.2.2

Question

I’m attempting to use the _tile_data_runtime_update() function to set the color/modulate of some of the tiles in the Atlas of my tilemap, but Godot keeps saying ‘Invalid call. Nonexistent function.’ when I try to run it.

This code looks like this:

var NewData = TileData.new()

var colors = [Color("ffffff"),Color("ffff00"),Color("00ff00"),Color("f5678f"),Color("f888ff"),Color("ffffff"),Color("ff0000")]
var base = colors[0]
var weapon1 = colors[1]
var weapon2 = colors[2]
var weapon3 = colors[3]
var weapon4 = colors[4]
var weapon5 = colors[5]
var player_trail = colors[6]

func _set_colors():
	var index = 3
	for  i in 7:
		NewData.modulate = colors[i]
		print(i)
		$TileMap.notify_runtime_tile_data_update(0)
		print($TileMap._use_tile_data_runtime_update(0,Vector2(4,index+i)))
		$TileMap._tile_data_runtime_update(0,Vector2(4,index+i),NewData)
	$TileMap.notify_runtime_tile_data_update(0)

It recognizes notify_runtime_tile_data_update(), but not _use_tile_data_runtime_update() or _tile_data_runtime_update(). ANyone know what’s wrong here?

those two functions are virtual, which means you define them, not Godot. Like _ready() or _enter_tree(), etc. So, first you create a subclass of TileMap, and in that subclass, define those functions and make sure _use_tile_data_runtime_update() properly returns true/false depending on if the specific tile co-ords passed to it as params needs the runtime_data stuff. And when that returns true, Godot will call your _tile_data_runtime_update function, which you also need to define, with the TileData that needs special sauce.

1 Like

oh and it seems that TileMap is soon to be replaced by TileMapLayer, which is only in 4.3 (beta, currently).

Maybe you’d like to have a look at that, from what I hear things changed up a good bit, and it might save you some hassle later to get out ahead of impending Big Changes to the TileMap game.

Thanks for the answer, was able to wrap my head around it after I slept, and was no longer on negative sleep. Got it to work by doing this:

func _set_colors(num):
	new_color = str(colors[num])
	var testy = get_used_cells(0)
	self.notify_runtime_tile_data_update(0)
	
	for i in (len(testy)-1):
		self._use_tile_data_runtime_update(0,testy[i])
	self.notify_runtime_tile_data_update(0)
	emit_signal("pog")

#If this returns true, Godot calls the next funtion automatically.
func _use_tile_data_runtime_update(layer: int, coords: Vector2i) -> bool:
	if startup:
		return startup
	if coord_list.has(coords):
		return true
	return false
	
func _tile_data_runtime_update(layer: int, coords: Vector2i, tile_data: TileData) -> void:  
	tile_data.modulate =  Color(new_color)

signal pog
var startup = true
var new_color = str("ffffff")
var coord_list = [Vector2i(-1,-1)]

func _set_list(list):
	coord_list = list

func _ready():
	_set_colors(0)
	await pog
	startup=false
	pass
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.