Can you make a signal multiple nodes can emit

Godot Version

Godot 4.4.1

Question

I’m trying to make a signal that one of my nodes listens to, but I want it to be able to take the signal from any other node. Currently, whenever I connect a signal, it adds the function shown as “on(node)_(signalname)”. How do I make it so any node can emit that signal?

Through the editor you can connect multiple nodes to the same function, just change the name to match or use the “pick” button.

3 Likes

There are three ways to do this.

First, as @gertkeno suggested, you can just name the signal the same thing in every Node you want to use it.

signal mysterious_signal

If you don’t want to add that to every file separately, you can make a base class to inherit from for each type like so:

class_name MysteriousSignalBase extends Node

signal mysterious_signal

Then use it like this:

extends MysteriousSignalBase

Second, as long as you have a reference to a node that has a signal, you can emit it.

var emitter_node = $SomeNode

emitter_node.mysterious_signal.emit()

Third, you can create a clearance house or conductor class, something all the general signal class flows through and make it an Autoload.

extends Node

signal mysterious_signal

When you make it an automload let’s say you call it Conductor. Then you could connect to it anytime.

Conductor.mysterious_signal.emit()
3 Likes

Thanks so much! Didn’t expect it to be that simple!

I’d go for the third option that @dragonforge-dev suggested. It takes a bit more to set up, but uncouples your objects and will be accessible from anywhere.

Thats what I do with all of my projects (C#), have a signals manager class that everything talks to.

2 Likes

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