Identify sender node of global signal

Godot Version

4.2.1

Question

I have a singleton event handler
I have a sender
I have a reciever

I just want to print out what node sent the signal, when the player steps into an Area 3d I want to know what AreaNode it is in.
I have googled and searched and found people with similar problems. But I can´t figure out anything useful from their answers.
I know Iḿ supposed to write something in the emit() but I keep getting errors like expected one arguement but recieved three.

func _ready() → void:
SignalBus.hello.connect(_on_hello_recieved)

func _on_hello_recieved():
print(“whoAmI?”)

Define your signal like this in your SignalBus:

signal hello(sender)

Emit the signal like this in your sender script:

SignalBus.hello.emit(self)

Now you are passing a reference to the sender node as an argument when emitting the signal.

Connect and receive the signal like this:

func _ready() -> void:
  SignalBus.hello.connect(_on_hello_received)

func _on_hello_received(sender):
  print(sender)
2 Likes

Thank you! My night has been saved from failure.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.