godot error invaild call. nonexistent function 'set_chunk_position' in base 'Spatial'

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

So i was watching this tutorial https://www.youtube.com/watch?v=Q2iWDNq5PaU&ab_channel=xen-42 and i keep getting this error godot error invaild call. nonexistent function ‘set_chunk_position’ in base ‘Spatial’

ill past my code so where i am trying to run the fuction

extends Spatial

var chunk_scene = preload(“res://chunck.tscn”)

var load_radius = 5
onready var chunks = $Chunks
onready var player = $Player

var load_thread = Thread.new()

func _ready():
for i in range(0, load_radius):
for j in range(0, load_radius):
var chunk = chunk_scene.instance()
chunk.set_chunk_position(Vector2(i, j))

load_thread.start(self, "_thread_process", null)

func _thread_process(_userdata):
for c in chunks.get_children():
var cx = c.chunk_position.x
var cz = c.chunk_position.y

		var px = floor(player.translation.x / Global.DIMENSION.x)
		var pz = floor(player.translation.z / Global.DIMENSION.z)
		var new_x = posmod(cx - px + load_radius/2, load_radius) + px - load_radius/2
		var new_z = posmod(cz - pz + load_radius/2, load_radius) + pz - load_radius/2
		if (new_x != cx or new_z != cz):
			c.set_chunk_position(Vector2(int(new_x), int(new_z)))

and when the function is

func set_chunk_position(pos):
chunk_position = pos
translation = Vector3(pos.x, 0, pos.y) * Global.DIMENSION

self.visible = false

thanks and sorry if its a bit long

:bust_in_silhouette: Reply From: Wakatta

All of your chunk scenes ("res://chunck.tscn") need to have a script
And that script needs to have the function set_chunk_position(pos):
So the problem you’re having is during the for loop one of the child nodes isn’t a chunk scene or does not have the necessary script attached.

:bust_in_silhouette: Reply From: zhyrin

nonexistent function ‘set_chunk_position’ in base ‘Spatial’

So what does this mean? It means you are trying to call a functioncalled set_chunk_position() on a variable that has a type Spatial, even though Spatial doesn’t have this function.

Where does this happen?

for c in chunks.getchildren():
    c.set_chunk_position(Vector2(int(new_x), int(new_z)))

The children in chunks will only have the function if you attach a script to them that implements it (or inherits from a class that does so).
Make sure all children of chunks actually has the proper script attached.