Cannot call method 'create_timer' on a nul

Godot V 4.1.2

Hello,
I’m a bit new to godot and I’m trying to make an evolution sim

when I run a pause I get this error : Cannot call method ‘create_timer’ on a null value.

func Pause(RNA, food):
	#await(owner.ready)
	await get_tree().create_timer(1).timeout
	update_life(RNA, food)

if I uncomment the await(owner.ready) the code waits forever

If it’s needed here is the code that creates the child

func Make_Thing(DNA, food):
	var thing_scene = preload("res://thing.tscn")
	var thing2 = thing_scene.instantiate()
	var setup = thing2.get_node("Sprite2D")  # Adjust the path as per your scene hierarchy
	DNA = [proteases, cellulase, thylakoids, move, fat, spike, shell, brain, MutationMod, SplitMod]
	setup.initialize_life(DNA, food)  # Call the setup_variables function
	thing2.position = Vector2(randf_range(75, 1140), randf_range(10, 640))
	add_child(thing2)

I guess Pause is called somewhere in initialize_life? If so, that’s the problem! For get_tree to work, you first have to add the respective node to a tree. That is, you would have to call add_child(thing2) before setup.initialize_life(DNA, food).

1 Like

This worked! Thank you so much!

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