From 0575cbe4504be195386701f337eea0da52ec1668 Mon Sep 17 00:00:00 2001 From: Jowan-Spooner <42868150+Jowan-Spooner@users.noreply.github.com> Date: Sat, 9 Dec 2023 11:34:17 +0100 Subject: [PATCH] Add prepare() method for styles that should preload scenes (#1945) The perpare() method should preload all the packed scenes needed for the particular style, thus fixing a lag-spike. Needs to be called manually right now. --- addons/dialogic/Modules/Style/subsystem_styles.gd | 7 ++++++- addons/dialogic/Resources/dialogic_style.gd | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/addons/dialogic/Modules/Style/subsystem_styles.gd b/addons/dialogic/Modules/Style/subsystem_styles.gd index a3774e273..92be0404c 100644 --- a/addons/dialogic/Modules/Style/subsystem_styles.gd +++ b/addons/dialogic/Modules/Style/subsystem_styles.gd @@ -86,7 +86,12 @@ func create_layout(style:DialogicStyle) -> DialogicLayoutBase: if not ResourceLoader.exists(layer.path): continue - var layer_scene : DialogicLayoutLayer = load(layer.path).instantiate() + var layer_scene : DialogicLayoutLayer = null + + if ResourceLoader.load_threaded_get_status(layer.path) == ResourceLoader.THREAD_LOAD_LOADED: + layer_scene = ResourceLoader.load_threaded_get(layer.path).instantiate() + else: + layer_scene = load(layer.path).instantiate() base_scene.add_layer(layer_scene) diff --git a/addons/dialogic/Resources/dialogic_style.gd b/addons/dialogic/Resources/dialogic_style.gd index a2a30ce5a..f0c1b29e0 100644 --- a/addons/dialogic/Resources/dialogic_style.gd +++ b/addons/dialogic/Resources/dialogic_style.gd @@ -185,3 +185,12 @@ func clone() -> DialogicStyle: style.add_layer(info.path, info.overrides) return style + + +func prepare() -> void: + if base_scene: + ResourceLoader.load_threaded_request(base_scene.resource_path) + + for layer in layers: + if layer.scene: + ResourceLoader.load_threaded_request(layer.scene.resource_path)