Signals between 2 scenes

Godot Version

v4.2.1.stable.official

Question

I am strugling with making siganl between 2 scenes.

One scene with button that should emit signal every time it’s pressed.

extends Control
signal slot_selected

func _on_item_button_pressed():
	print("Press")
	slot_selected.emit()

And another one that should recieve that signal.

extends Control
@onready var inventory_slot = load("res://Scenes/Inventory_Slot.tscn").instantiate()

func _ready():
inventory_slot.slot_selected.connect(_on_slot_selected)

func _on_slot_selected():
	print("Slot Selected")

Also I tried this variation:

extends Control
@export var scene: PackedScene

func _ready():
	var set_scene = scene.instantiate()
	add_child(set_scene)
	set_scene.slot_selected.connect(_on_slot_selected)

func _on_slot_selected():
	print("Slot Selected")

I’ve looked at a lot of tutorials on YT and similar topics here, but I haven’t been able to solve this problem. Please tell me, is it possible to make a signal between 2 scenes and how?

The code should work, so the problem must be elsewhere.

Does “Press” get printed, when you test the signal?

Is your button’s signal connected to this function?

Yes, I can’t get the “Slot Selected” to be printed tho

Yes, it is connected and print out.

Do you have any errors in the console ? Like null pointer exception or anything else ?

No, but there are some errors when I try to autoload this scene. Let me show you.
The scene that emit signal:
image
I tried to autoload it and I get this error:

  Failed to instantiate scene state of "res://Scenes/Inventory_Slot.tscn", node count is 0. Make sure the PackedScene resource is valid.
  Failed to create an autoload, path is not pointing to a scene or a script: res://Scenes/Inventory_Slot.tscn.
  editor/editor_autoload_settings.cpp:550 - Condition "!info->node" is true. Continuing.
Add Autoload

Maybe it is the problem?

I’m not sure but it’s a good start

1 Like