44 lines
1.6 KiB
GDScript3
44 lines
1.6 KiB
GDScript3
|
extends Node
|
||
|
|
||
|
var current_scene = null
|
||
|
var character = null
|
||
|
var character_camera = null
|
||
|
var character_creation_camera = null
|
||
|
|
||
|
func _ready():
|
||
|
var root = get_tree().get_root()
|
||
|
current_scene = root.get_child(root.get_child_count() -1)
|
||
|
|
||
|
character = get_tree().get_root().get_node( "Main/Game/Character" )
|
||
|
character_camera = get_tree().get_root().get_node( "Main/Game/Character/Camera_rotation_helper/Camera" )
|
||
|
character_creation_camera = get_tree().get_root().get_node( "Main/GUI/character_creation_menu/v_box_container/h_box_container/center_container/character_creation_scene/camera" )
|
||
|
|
||
|
func goto_scene(path):
|
||
|
# This function will usually be called from a signal callback,
|
||
|
# or some other function from the running scene.
|
||
|
# Deleting the current scene at this point might be
|
||
|
# a bad idea, because it may be inside of a callback or function of it.
|
||
|
# The worst case will be a crash or unexpected behavior.
|
||
|
|
||
|
# The way around this is deferring the load to a later time, when
|
||
|
# it is ensured that no code from the current scene is running:
|
||
|
|
||
|
call_deferred("_deferred_goto_scene", path)
|
||
|
|
||
|
|
||
|
func _deferred_goto_scene(path):
|
||
|
# Immediately free the current scene,
|
||
|
# there is no risk here.
|
||
|
current_scene.free()
|
||
|
|
||
|
# Load new scene.
|
||
|
var s = ResourceLoader.load(path)
|
||
|
|
||
|
# Instance the new scene.
|
||
|
current_scene = s.instance()
|
||
|
|
||
|
# Add it to the active scene, as child of root.
|
||
|
get_tree().get_root().add_child(current_scene)
|
||
|
|
||
|
# Optional, to make it compatible with the SceneTree.change_scene() API.
|
||
|
get_tree().set_current_scene(current_scene)
|