Godot: Object#has_user_signal with signal keyword

Created on 23 Jul 2017  路  6Comments  路  Source: godotengine/godot

Operating system or device - Godot version:
Arch Linux - 3.0 [25678b187]

Issue description:
Using Object#has_user_signal does not work for signals using the signal keyword. It requires them to be explicitly added via Object#add_user_signal.

Steps to reproduce:

For example this prints false:

signal foo
func _ready():
    print(self.has_user_signal("foo"))

while this prints true:

signal foo
func _ready():
    self.add_user_signal("foo")
    print(self.has_user_signal("foo"))

Of course the signal foo line is unnecessary in the second case, but this is the new syntax as I understand it.

bug gdscript

Most helpful comment

Same here, just had the same issue when working on a 2.1.4 project, can't test presence of signal.
I wonder why there isn't just a has_signal...

All 6 comments

Another workaround is using node.get_signal_connection_list("foo").size() > 0, though it's of course more verbose. But it might be better, since I found out that calling add_user_signal only works as in my example above if you call it _before_ you call connect for the same signal name.

Maybe we should add an additional has_signal method?

Maybe we should add an additional has_signal method?

What is the difference between a user signal and a script signal? Why do we need 2 different functions?
Can't we register script signals as user signals when initing?

The right way to fix this is with node.get_script().has_script_signal() . It was not available in GDScript, so adding it right now..

I'm with @Faless on this and don't understand the user vs script signal distinction.

Same here, just had the same issue when working on a 2.1.4 project, can't test presence of signal.
I wonder why there isn't just a has_signal...

Was this page helpful?
0 / 5 - 0 ratings