From 8be627e168a421364b207328cbc618603ce11094 Mon Sep 17 00:00:00 2001 From: myin Date: Thu, 7 Sep 2023 18:06:33 +0200 Subject: [PATCH 1/2] add support for packed scene --- addons/scene_manager/SceneManager.gd | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/addons/scene_manager/SceneManager.gd b/addons/scene_manager/SceneManager.gd index df09009..e600115 100644 --- a/addons/scene_manager/SceneManager.gd +++ b/addons/scene_manager/SceneManager.gd @@ -98,7 +98,7 @@ func _process(_delta: float) -> void: _previous_scene = _tree.current_scene func change_scene(path: Variant, setted_options: Dictionary = {}) -> void: - assert(path == null or path is String, 'Path must be a string') + assert(path == null or path is String or path is PackedScene, 'Path must be a string or a PackedScene') var options = _get_final_options(setted_options) if not options["skip_fade_out"]: await fade_out(setted_options) @@ -123,10 +123,10 @@ func fade_in_place(setted_options: Dictionary = {}) -> void: setted_options["no_scene_change"] = true await change_scene(null, setted_options) -func _replace_scene(path: String, options: Dictionary) -> void: +func _replace_scene(path: Variant, options: Dictionary) -> void: _current_scene.queue_free() scene_unloaded.emit() - var following_scene: PackedScene = ResourceLoader.load(path, "PackedScene", 0) + var following_scene: PackedScene = _load_scene_resource(path) _current_scene = following_scene.instantiate() _current_scene.tree_entered.connect(options["on_tree_enter"].bind(_current_scene)) _current_scene.ready.connect(options["on_ready"].bind(_current_scene)) @@ -134,6 +134,11 @@ func _replace_scene(path: String, options: Dictionary) -> void: _root.add_child(_current_scene) _tree.set_current_scene(_current_scene) +func _load_scene_resource(scene: Variant) -> Resource: + if path is PackedScene: + return path + return ResourceLoader.load(path, "PackedScene", 0) + func fade_out(setted_options: Dictionary= {}) -> void: var options = _get_final_options(setted_options) is_transitioning = true From 091b5c483a02e5211a7534cfb1c98013e4851c77 Mon Sep 17 00:00:00 2001 From: myin Date: Thu, 7 Sep 2023 18:09:53 +0200 Subject: [PATCH 2/2] fix parameter name --- addons/scene_manager/SceneManager.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/scene_manager/SceneManager.gd b/addons/scene_manager/SceneManager.gd index e600115..e7bcc19 100644 --- a/addons/scene_manager/SceneManager.gd +++ b/addons/scene_manager/SceneManager.gd @@ -134,7 +134,7 @@ func _replace_scene(path: Variant, options: Dictionary) -> void: _root.add_child(_current_scene) _tree.set_current_scene(_current_scene) -func _load_scene_resource(scene: Variant) -> Resource: +func _load_scene_resource(path: Variant) -> Resource: if path is PackedScene: return path return ResourceLoader.load(path, "PackedScene", 0)