Custom Signal Between disconnected scenes

Godot Version

Godot Engine v4.2.2.stable

Question

Hello everyone,

In my game there is a team selection scene as starter, and there are two buttons that when pressed sets the team and changes a boolean variable to true, so i can change scene. And in here i emit a signal with parameter selected_team.

There is a photo of what i described down below. Hope you can see it.

And then i go to my main scene where player and enemies exist. I am trying to receive the signal i send but i could not make it work properly, I guess i connect it because when i put “connect” line in _process function it keeps telling me that it is already connected. Anyway i am sending the merged photo that contains the two scripts what i mentioned

And to emit and connect this signal i am using a singleton that i autoload. and it just includes these two lines:

extends Node

signal team_selected(selected_team)

Can you help me out here? I’ve tried some stuff but i couldn’t resolve the issue.

Important Note: These scenes (first_scene and character scene) does not share a parent node, they are seperated scenes.

Hi!
You should connect to the signal in the _ready function. Otherwise, if you connect each time _process is invoked then there will already be a connection from the second frame forward.

1 Like

Yeah, I know I just tried it to see what happens and it didn’t work. Expected really. Do you have any suggestions on the problem? Why it does not work? Should i make them have a common parent?

I am wondering the same thing: how do you connect signals between scenes that aren’t in the same SceneTree (no common parent)?

My workaround was to create an Autoload script (Singleton) and use that to keep information that is common to multiple scenes. However, if you have to update variables or UI elements (like HUD), then you have to have a way to periodically poll the global variables in the Autoload script. I tried doing this using the _process method in my HUD scene, but that just felt wrong- although my computer didn’t complain about it at all.

I think, ultimately, that if you want to communicate between scenes, you really need to have those scenes in a common SceneTree (same parent node). Then you can run scripts in other scenes using get_parent() and get_node().