Skip to content

Commit

Permalink
XRToolsStaging: warn on missing scene container
Browse files Browse the repository at this point in the history
The user should add a child Node3D and set it
as the property of XRToolsStaging in order to
be used to contain the current scene.

Fix issue GodotVR#628
  • Loading branch information
esodan committed Apr 1, 2024
1 parent f8638ad commit dd24895
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions addons/godot-xr-tools/staging/staging.gd
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,21 @@ signal xr_ended


## Main scene file
@export_file('*.tscn') var main_scene : String
@export_file('*.tscn') var main_scene : String:
set(value):
main_scene = value
update_configuration_warnings()

## If true, the player is prompted to continue
@export var prompt_for_continue : bool = true

## Scene container file as a Node3D used as
## the parent of the current scene.
@export var scene_container : Node3D:
set(value):
scene_container = value
update_configuration_warnings()


## The current scene
var current_scene : XRToolsSceneBase
Expand All @@ -93,6 +103,8 @@ func _ready():
if xr_camera:
$LoadingScreen.set_camera(xr_camera)

update_configuration_warnings()

# We start by loading our main level scene
load_scene(main_scene)

Expand All @@ -119,6 +131,9 @@ func _get_configuration_warnings() -> PackedStringArray:
if !FileAccess.file_exists(main_scene):
warnings.append("Main scene doesn't exist")

if not scene_container:
warnings.append("No Node3D child, named \"Scene\" has been added")

# Return warnings
return warnings

Expand Down Expand Up @@ -166,7 +181,7 @@ func load_scene(p_scene_path : String, user_data = null) -> void:
# Now we remove our scene
emit_signal("scene_exiting", current_scene, user_data)
current_scene.scene_exiting(user_data)
$Scene.remove_child(current_scene)
scene_container.remove_child(current_scene)
current_scene.queue_free()
current_scene = null

Expand Down Expand Up @@ -241,7 +256,7 @@ func load_scene(p_scene_path : String, user_data = null) -> void:
# Setup our new scene
current_scene = new_scene.instantiate()
current_scene_path = p_scene_path
$Scene.add_child(current_scene)
scene_container.add_child(current_scene)
_add_signals(current_scene)

# We create a small delay here to give tracking some time to update our nodes...
Expand Down

0 comments on commit dd24895

Please sign in to comment.