Skip to content

Commit

Permalink
Add prepare() method for styles that should preload scenes (#1945)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jowan-Spooner authored Dec 9, 2023
1 parent 25d22af commit 0575cbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion addons/dialogic/Modules/Style/subsystem_styles.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions addons/dialogic/Resources/dialogic_style.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 0575cbe

Please sign in to comment.