I wasn't sure how to handle that since I'm trying out a Global autoload that sorts out scenes.
This is my current Global Script:
extends Node
var coins := 0
const NUM_COINS_TO_WIN = 10
var game_controller : GameController
func _ready() -> void:
pass
My GameController Script:
class_name GameController extends Node
@export var world_3d : Node3D
@export var world_2d : Node2D
@export var gui : Control
var current_3d_scene
var current_2d_scene
var current_gui_scene
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Global.game_controller = self
current_gui_scene = get_tree().change_scene_to_file("res://menu.tscn")
func change_gui_scene(new_scene: String, delete: bool = true, keep_running : bool = false) -> void:
if current_gui_scene != null:
if delete:
current_gui_scene.queue_free() #removes node entirely
elif keep_running:
current_gui_scene.visible = false #keeps in memory and running
else:
gui.remove_child(current_gui_scene) #keeps in memory, does not keep running
var new = load(new_scene).instantiate()
gui.add_child(new)
current_gui_scene = new
func change_3d_scene(new_scene: String, delete: bool = true, keep_running : bool = false) -> void:
if current_3d_scene != null:
if delete:
current_3d_scene.queue_free() #removes node entirely
elif keep_running:
current_3d_scene.visible = false #keeps in memory and running
else:
world_3d.remove_child(current_3d_scene) #keeps in memory, does not keep running
var new = load(new_scene).instantiate()
world_3d.add_child(new)
current_3d_scene = new
func change_2d_scene(new_scene: String, delete: bool = true, keep_running : bool = false) -> void:
if current_2d_scene != null:
if delete:
current_2d_scene.queue_free() #removes node entirely
elif keep_running:
current_2d_scene.visible = false #keeps in memory and running
else:
world_2d.remove_child(current_2d_scene) #keeps in memory, does not keep running
var new = load(new_scene).instantiate()
world_2d.add_child(new)
current_2d_scene = new
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
and my GameManager script I used to pause a scene:
extends Node
class_name GameManager
signal toggle_game_paused(is_paused : bool)
var game_paused : bool = false:
get:
return game_paused
set(value):
game_paused = value
get_tree().paused = game_paused
emit_signal("toggle_game_paused", game_paused)
func _input(event: InputEvent) -> void:
if (event.is_action_pressed("pause")):
print("Pause Button Pressed")
game_paused = !game_paused