Invalid call to function 'get_cell_tile_data' in base 'TileMapLayer'. Expected 1 arguments.

Godot Version

Replace this line with your Godot version

Question

I’m following this tutorial on YouTube and I ran into a problem, i tried my best to solve it by myself but nothing i do work. here’s the error Invalid call to function ‘get_cell_tile_data’ in base ‘TileMapLayer’. Expected 1 arguments.

YouTube link

the link to the tutorial https://youtu.be/DkAmGxRuCk4?si=oaqlOrb7Z7Fxj44_

Code

extends CharacterBody2D

@onready var tile_map_layer = $“../TileMapLayer”
var astar_grid: AStarGrid2D
var current_id_path: Array[Vector2i]

Called when the node enters the scene tree for the first time.

func _ready():
astar_grid = AStarGrid2D.new()
astar_grid.region = tile_map_layer.get_used_rect()
astar_grid.cell_size = Vector2(12, 12)
astar_grid.diagonal_mode =AStarGrid2D.DIAGONAL_MODE_NEVER
astar_grid.update()

for x in tile_map_layer.get_used_rect().size.x:
	for y in tile_map_layer.get_used_rect().size.y:
		var tile_position = Vector2i(
			x + tile_map_layer.get_used_rect().position.x,
			y + tile_map_layer.get_used_rect().position.y
		)
		
		var tile_data = tile_map_layer.get_cell_tile_data(0, tile_position)
		
		
		if tile_data == null or tile_data.get_custom_data("walkable") == false:
			astar_grid.set_point_solid(tile_position)

func _input(event):
if event.is_action_pressed(“move”) == false:
return

var id_path = astar_grid.get_id_path(
	tile_map_layer.local_to_map(global_position),
	tile_map_layer.local_to_map(get_global_mouse_position())
).slice(1)

if id_path.is_empty() == false:
	current_id_path = id_path

func _physics_process( _delta):
if current_id_path.is_empty():
return

var target_position = tile_map_layer.map_to_local(current_id_path.front())

global_position = global_position.move_toward(target_position, 1)

if global_position == target_position:
	current_id_path.pop_front()

var tile_data = tile_map_layer.get_cell_tile_data(0, tile_position)
This video is made using Godot prior to the change from TileMap to TileMapLayer.
In the latest version get_cell_tile_data only uses the cell position since it is a method of a TileMapLayer and the old function used the Layer as parameter 1.
You are going to have to make some changes if you want to follow along using a later version of Godot.
Or you can download an older version of Godot (4.2 I think is the last one with TileMap) and follow along.

And also, you need to use the code formatting tags to post code here. The easiest way to do that is to select the code and click on the menu icon that looks like this </>

what kind of changes do I have to make? and is downloading a older version of Godot necessary for the tutorial to work? also thanks for your patience, for your time and for your understanding.

I never knew you could do that but again thank you for the advice, I really appreciate you teaching me how to use the menu.

Well, it is a pretty big change in tilemap handling from 4.2 to 4.3+, but everything else should work.
In the older version the TileMap contained layers defined by the coder.
In the newer version each tile map is a layer; a TileMapLayer

Try going forward with the tutorial and when things break (like you posted here), then you can post specific questions.
For now the change you need to make is that line:
var tile_data = tile_map_layer.get_cell_tile_data(tile_position)

But also know that downloading and running an older version of Godot is trivial. Godot runs as a single executable without an installer.

I suppose there is also another option. You could try to message the video author and see if he would be willing to update it to the new tile map system.