Hi,
I've been using the Custom scene switcher from the documentation in some projects and I think it is a bit overkill considering the methods that SceneTree offers.
I've replaced this global.gd script:
extends Node
var current_scene = null
func _ready():
var root = get_tree().get_root()
current_scene = root.get_child( root.get_child_count() -1 )
func goto_scene(path):
call_deferred("_deferred_goto_scene",path)
func _deferred_goto_scene(path):
current_scene.free()
var s = ResourceLoader.load(path)
current_scene = s.instance()
get_tree().get_root().add_child(current_scene)
get_tree().set_current_scene( current_scene )
by this one:
extends Node
var current_scene = null
var new_scene = null
func _ready():
var root = get_tree().get_root()
current_scene = root.get_child( root.get_child_count() -1 )
pass
func goto_scene(path):
var s = ResourceLoader.load(path)
new_scene=s.instance()
get_tree().get_root().add_child(new_scene)
get_tree().set_current_scene(new_scene)
current_scene.queue_free()
current_scene=new_scene
It seems to work properly.
Does anyone foresee any problem with this method? (tested only on simple scene switching).