Avoid adding loaded scene to tree until all loading is finished.
Some checks failed
linting & formatting / build (push) Failing after 32s
itch.io publish action / build (linux64, x86_64) (push) Successful in 2m22s
itch.io publish action / build (osx, app) (push) Successful in 2m24s
itch.io publish action / build (win64, exe) (push) Successful in 2m30s

This commit is contained in:
Rob Kelly 2025-09-07 01:45:25 -06:00
parent 35a03797f7
commit 667aa38cda
4 changed files with 15 additions and 2 deletions

View File

@ -3,6 +3,6 @@ extends Node
@export_file("*.tscn") var initial_scene := "res://src/world/world.tscn"
func _ready() -> void:
func _init() -> void:
print("Starting from editor-only entrypoint.")
Game.instance.queue_scene(initial_scene)

View File

@ -4,6 +4,7 @@ class_name Game extends Node
@export_file("*.tscn") var start_scene: String
var _loading_resources: Dictionary[String, Promise] = {}
var _queued_content: Node
@onready var content: Node = %Content
@onready var loading_screen: Control = %LoadingScreen
@ -89,6 +90,10 @@ func _unload_content() -> void:
func _finish_scene_load(scene_instance: Node) -> void:
_queued_content = scene_instance
func _add_scene_content(scene_instance: Node) -> void:
# Unpause in case the previous scene was paused.
get_tree().paused = false
# Reset time scale in case it's been changed.
@ -115,5 +120,11 @@ func _process(_delta: float) -> void:
# Continue loading
pass
if not _loading_resources:
# Delay adding queued scene to the tree until loading is finished
if _queued_content:
_add_scene_content(_queued_content)
_queued_content = null
if not _loading_resources:
loading_screen.visible = false

View File

@ -9,14 +9,17 @@ static func _load_world(level: PackedScene, save: SaveState = null) -> void:
world.save_state = save
world.initial_level = level
print_debug("Loading world")
Game.instance.queue_scene(WORLD_SCENE).then(finish_load)
static func load_level(level_path: String, save: SaveState = null) -> void:
print_debug("Loading level from ", level_path)
var chain_load := func(level: PackedScene) -> void: LoadingTools._load_world(level, save)
Game.instance.queue_load(level_path).then(chain_load)
static func load_save(save_path: String) -> void:
print_debug("Loading save from ", save_path)
var chain_load := func(save: SaveState) -> void: load_level(save.level_path, save)
Game.instance.queue_load(save_path, ResourceLoader.CACHE_MODE_REPLACE_DEEP).then(chain_load)

View File

@ -13,7 +13,6 @@ volume_db = -14.0
[node name="World" type="Node"]
script = ExtResource("1_1k4gi")
pause_enabled = null
manager = ExtResource("2_5kmgb")
spook_manager = ExtResource("3_l0av5")
pause_music_effect = SubResource("AudioEffectAmplify_5kmgb")