How to obtain a user signal reference from a node?

Godot Version

4.3

Question

I have a “signal bus” autoload called Signals to which I add signals programmatically, thus:

Signals.add_user_signal("Example_signal")

Later on, in a different node, I can verify that Signals has the signal added:

var has_signal := Signals.has_user_signal("Example_signal")

I have a C# API method called “AddSignal” that expects a gdscript signal reference, but I can’t seem to find a way to get a signal reference from my Signals autoload. I’m looking for an object method like:

csh_obj.AddSignal(Signals.Example_signal)  # produces error

The error is: Invalid access to property or key 'Example_signal on a base object of type ‘Node (signals.gd)’.

Likewise, it seems like the get or get_indexed methods might work (they don’t produce errors) but they don’t return a usable signal reference, either. The method I really want is:

Signals.get_user_signal("Example_signal")

But, this doesn’t exist.

Is there a way of doing what I want?

Edit: Just to be clear, this is not a show-stopper sort of problem. I have other ways to get where I’m going… I just thought there should be a way to do this!

So your problem is referencing C# code from GDScript and vice versa? Did you check this article?

Thanks! I am familiar with that. I’m currently using this C# API using gdscript signals that are explicitly declared. For example:

csh_obj.AddSignal($"../Path/To/Gdscript/Node".Example_signal)

This works fine, but I also have the dynamically added user signals in the signal bus that I would like to use with it too.

How do you do that exactly? Can you share your code from this Signals.add_user_signal() method?

Ah… it’s actually a method of Object: add_user_signal

Ah, ok, I thought this is your custom method.
I don’t think there is a way to retrieve a Signal object from the “user” signal added through code, the only way I see that is to reference it by StringName instead of Signal.
You can create a new proposal for it if you see the value:

1 Like