Get_tree().reload_current_scene() crashes game

Godot Version

4.2.1

Question

Hello Godoteers!

I am trying to reset my prototype/main game scene when current_health reaches zero and doing this via a signal from sandbox.gd (attached to vehicle_parent node) to main_world.gd (attached to World).

I am using get_tree().reload_current_scene() to reload the main scene but the game goes grey and crashes. The only errors that are thrown are timer related ones that can’t complete because the game has stopped.

I have also tried get_tree().reload_scene("res://Example World/Objects/World/world.tscn") to reload the scene but get the same results.

Any help, ideas, tips would be greatly appreciated! Cheers!

(the window goes grey)

(main scene tree)
image

sandbox.gd attached to Vheicle_parent node

func zombie_melee_attack(Melee_Damage):
	print("zombie_melee_attack signal picked up by sandbox.gd")
	current_health -= Melee_Damage
	current_health = max(0, current_health)
	emit_signal("health_changed", current_health)
	if current_health <= 0:
		emit_signal("health_zero")

main_world.gd attached to World node

func _on_vehicle_parent_health_zero():
	get_tree().reload_current_scene()

You can return the value from the reload function, and print it out or just use the debugger to see if actually any error is happening:

 Error reload_current_scene()

Reloads the currently active scene.

Returns OK on success, ERR_UNCONFIGURED if no current_scene was defined yet, ERR_CANT_OPEN if current_scene cannot be loaded into a PackedScene, or ERR_CANT_CREATE if the scene cannot be instantiated

Thank you @bananaholograma! I am not getting any errors related to the reload function when the game crashes. Is there a way I can make sure they will show up when get_tree().reload_current_scene() is called? Sorry for not understanding.

Try this:

var err = get_tree().reload_current_scene()
print(err)

I guess you are trying it in a particular scene and it doesn’t work, try it in a new created scene with very little logic and see if it works.

If it does, you’ll have to check your code and see what might be affecting the scene instance.

1 Like

thanks @tayacan ! Oddly enough err returns “0” when the scene crashes. Any idea what that could mean for debugging purposes?

Nope! Could try running godot in console mode and see if anything useful pops up in the console?

1 Like

I had an await that was trying to fire after during the reload and that was crashing the game. I if conditioned it out “if get_tree():” and that fixed things.

Thanks y’all!