I am trying to trigger a signal with parameters but I am struggling to figure this out. Basically, I have 2 scenes (menu and play) and I have a scene controller scene as well.
Here is an example of my tree:
SceneController:
Menu:
Play:
Scene controller has it's own script, and menu has it's own script (referenced below). There is a "play" button on the menu scene.
On my menu scene:
extends Control
signal change_scene(scene_name)
var scene_name: String = ""
func _on_btn_play_pressed():
scene_name = "play"
emit_signal("change_scene", scene_name)
and on my scene controller:
extends Node
@onready var current_scene = $MenuScene
func _ready():
current_scene.change_scene.connect(self.handle_level_change)
func _process(delta):
pass
func handle_level_change(target_scene_name: String):
var next_scene
match target_scene_name:
"menu":
next_scene = load("res://scenes/MenuScene.tscn").instance()
"play":
next_scene = load("res://scenes/GameScene.tscn").instance()
_:
return
add_child(next_scene)
current_scene.queue_free()
current_scene = next_scene
My goal is, when the play button is pressed, then the scene will change to the play scene. I want this to be managed from the scene controller and load the scenes as child nodes.
During debug, everything on the menu is happening properly, and the signal_emit is happening with the assigned variable. However, the scene controller is never seeing the signal.
Any help would be greatly appreciated.