This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Can I connect a signal without knowing the node, but only using the signal's name? Something like:

NodeA:#===================#
signal  Update_The_Popcorn

func OnTouchToast():
    Emit_Signal("Update_The_Popcorn")

NodeB:#===============================================#
ready():
    connect("Update_The_Popcorn",self,"Signal_Digest")

func Signal_Digest(SIGNAL):
    match SIGNAL_RECEIVED:
        "Update_The_Popcorn": $Popcorn.Implode()
in Engine by (381 points)

3 Answers

+1 vote
Best answer

As far as I know, no. There are however two ways to circumvent this problem that I can think of.
1) Add an intermediary node that will listen for the signals. For example, if you don't know who emits signal A, just use the _ready function of signal A emitters to connect to the intermediary listener, and then the listener will relay signal B to signal B listeners upon receiving signal A.

2) Find a way to make a node just listen for a signal directly, so that no matter who emits signal A, all signal A listeners will react.

by (141 points)
selected by

Having a intermediary node was something I thought about doing with autoloads or using groups, it works, thanks for the suggestions, cheers.

+1 vote

AFAIK, you must call connect() on the object with the signal you'd like to connect to. In your example, you're trying to connect a method of NodeB to a signal of NodeB. You'd have to do something like:

var nodea = NodeA.new()
node
a.connect("UpdateThePopcorn", self, "Signal_Digest", [SIGNAL])

by (190 points)
+1 vote

http://www.video-games.io/blog/

A signal manager to handle all the signals in the game. Super easy. Hope that helps

by (838 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.