thread + reload_current_scene() (solved)

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

Hello ! Thanks to ICatRegister, I now have a thread loading my ingame scene like that :

thread.start(self,"prep_scene", ResourceLoader.load_interactive("res://scenes/ingame.tscn"))

func _on_load_level_done():
	var level_res = thread.wait_to_finish()
	var scene = level_res.instance();
	goto_scene(scene);

func goto_scene(new_scene):
   	current_scene.queue_free()
	current_scene = new_scene
	get_tree().get_root().call_deferred("add_child",current_scene)  

.
It all works perfectly fine. It launches the ingame scene, but then my restart button, set in the ingame scene’s script, doesn’t work anymore :

func on_restartbutton_pressed():
     get_tree().reload_current_scene()

I’d like it to reload the ingame scene but it looks like my ingame scene is not recognize as “current_scene”.
do you know what I could replace this command with ?

thanks !

:bust_in_silhouette: Reply From: hilfazer

You didn’t set current_scene for SceneTree. Try adding this at the end of your goto_scene():

get_tree().call_deferred("set_current_scene", current_scene)

case solved, thanks ! :wink:

nonomiyo | 2018-07-18 16:02