Reload_current_scene() not working

Godot Version

4.2.1

Question

Hello, I’m trying to reload the main scene when my player dies (when the variable vida gets to 0) but using get_tree().reload_current_scene() is giving me the following error:
Cannot call method ‘reload_current_scene’ on a null value.

This is my code:

if vida <= 0:
		$"../CanvasLayer/ColorRect2/AnimationPlayer".play("restart")
		has_died = true
		died.emit()
		await $"../CanvasLayer/ColorRect2/AnimationPlayer".animation_finished
		get_tree().reload_current_scene()

Does anybody know how to do this?

Thanks.

Could it be that you call this code from a node that isn’t a part of the scene tree? In such a case, get_tree() probably returns null.

1 Like

Hello, thanks for your reply.

This node is a child of the main scene.

This is very strange because I tried calling the reload_current_scene() function in other part of the script and it worked, but here, it doesn’t. :confused:

You should provide and the node tree and the line where the error happens.

When it says null, yadda yadda, it means you have not got what u think u have.