Signals after switching scenes

Godot Version

Godot 4.6.stable.mono.official

Question

Hi! I’m currently trying to send signals using an autoloader between two different scenes after pressing a button, but after changing the way I would change a scene after pressing the button (from instantiating and add_childing to get_tree().change_scene_to_file), the signal just wouldn’t come through on the second scene. I put a signal received print test on the second scene to see if it would come through for clarification.

Appreciate any help :slight_smile:

Scene 1:

extends Node2D

@onready var fade = $"../fade"

# Character pool with pull rates
var characters = [
	{"name": "Common Sword", "rarity": "Common", "rate": 50.0},
	{"name": "Common Shield", "rarity": "Common", "rate": 0.0},
	{"name": "Rare Bow", "rarity": "Rare", "rate": 50.0},
	{"name": "Epic Staff", "rarity": "Epic", "rate": 0.0},
	{"name": "Legendary Dragon", "rarity": "Legendary", "rate": 0.0}
]

func _ready():
	
	randomize()

# Call this function to perform a pull
func pull():
	# Get total of all rates
	var total = 0.0
	for char in characters:
		total += char.rate
	
	# Random number
	var roll = randf() * total
	
	# Find which character was pulled
	var current = 0.0
	for char in characters:
		current += char.rate
		if roll <= current:
			
			print("★ You pulled: " + char.name + " [" + char.rarity + "]")
			GameManager.pull_completed.emit(char.name, char.rarity)
			return char
			
	return characters[0]
func _on_button_pressed():
	
	await fade.fade(2.0, 1.5).finished
	await fade.fade(0.0, 1.5).finished
	get_tree().change_scene_to_file("res://Assets/Scenes/animation_pre_results.tscn")
	pull()
	

Scene 2:

extends Node2D

@onready var fade = $"../fade"
@onready var _animated_sprite = $AnimationPlayer/AnimatedSprite2D
var current_level = Node2D

func _ready():
	
	GameManager.pull_completed.connect(data_received)
	
# Called when the node enters the scene tree for the first time.
func data_received(char_name: String, char_rarity: String):
	print("signal received")
func _on_button_pressed():
	
	
	await fade.fade(2.0, 1.5).finished
	await fade.fade(0.0, 1.5).finished
	get_tree().change_scene_to_file("res://Assets/Scenes/node_2d.tscn")
	

Autoloader Script:

extends Node

signal pull_completed(char_name: String, char_rarity: String)


func _ready():
	add_to_group("autoload")

SceneTree.change_scene_to_file() frees the scene immediately but this doesn’t mean that the new scene will be ready by then. You are connecting to the signal in the _ready() method which is too late by then as the signal has already been emitted. Try connecting to the signal in the Object._init() method instead.