Hi ! I have 3 scenes (titlescreen, waitingroom & ingame) and I've been trying to smoothly load the ingame.tscn when clicking a button on the titlescreen.
Happycamper helped me with some lines of code (thx!), but I'm still not understanding how to deal with threads....
this is what I have in the titlescreen scene script :
func _on_loadbutton_pressed():
get_node("/root/global").goto_scene("res://scenes/ingame.tscn",true)
and in the global.gd singleton :
extends Node
onready var thread = Thread.new()
onready var current_scene = get_node("/root/titlescreen")
func goto_scene(new_scene,loading):
current_scene.queue_free()
current_scene = new_scene
get_tree().get_root().call_deferred("add_child",current_scene)
if(loading):
thread.start(self,"prep_scene")
func prep_scene(userdata):
var s = ResourceLoader.load("res://scenes/waitingroom.tscn")
var scene = s.instance()
goto_scene(scene,false)
thread.call_deferred('wait to finish')
All it does at the moment is clear the titlescreen, but there's no waitingroom nor ingame scene appearing. I don't know what to put instead of 'wait to finish' in the call_deferred, and don't see where the code is checking the progression of the loading of the ingame scene...
Can someone please make it a bit clearer for me ? :/