Godot Version
4.5
Question
How can I link a signal between different scenes/using code?
I need to send various signals between scenes. In each case, the signal is emitted by a scene which is instantiated in the scene that the signal needs to reach. Here is an example of one approach that I tried:
@player.gd:
if event.is_action_pressed("pause"):
paused.emit()
@pause_screen.gd:
@onready var player = get_node("/root/Level1/Player")
func _ready() -> void:
player.connect("paused", _on_pause)
func _on_pause():
Globals.paused = true
visible = true
When trying to run this, the following error occurs (the program still launches though):
E 0:00:01:034 pause_screen.gd:6 @ _ready(): In Object of type âCharacterBody2Dâ: Attempt to connect nonexistent signal âpausedâ to callable âControl(PauseScreen)::_on_pauseâ.
<C++ Error> Condition â!signal_is_validâ is true. Returning: ERR_INVALID_PARAMETER
<C++ Source> core/object/object.cpp:1526 @ connect()
pause_screen.gd:6 @ _ready()
An alternative syntax I have tried:
@player.gd
# same as above
if event.is_action_pressed("pause"):
paused.emit()
@pause_screen:
func _ready() -> void:
player.paused.connect("paused", _on_pause)
This returns a separate error which I believe Iâve encountered before but never know how to deal with.
E 0:00:01:106 PauseScreen._ready: Invalid access to property or key âpausedâ on a base object of type âCharacterBody2Dâ.
pause_screen.gd:6 @ PauseScreen._ready()
pause_screen.gd:6 @ _ready()
Please help. There is no documentation on this that I can find.
