object.has_user_signal() returning false even though signal in object.get_signal_list()

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By andrew.s

I have a signal called “change_health” defined in a KinematicBody2D (the player):

signal change_health

However, when I want to check if this specific signal exists when a projectile hits it, I get a false result. BUT the signal appears to exist in the .get_signal_list() method.

func _on_Area2D_body_entered(body):
#	print(body.name)
#	print("Has method:\t %s" % body.has_method("set_health"))
	print("Has signal:\t %s" % body.has_user_signal("change_health"))
	print(body.get_signal_list())
	print("\n")

Here’s the output:

Has signal:	 False
[{args:[], default_args:[], flags:1, id:0, name:change_health, return:{class_name:, hint:0, hint_strin[...]

The first signal in the list is the “change_health” signal I am looking for, but .has_user_signal returns false. Any explanation on what I could be doing wrong?

same in godot 3.2

pow_n_eed | 2020-02-03 14:32

:bust_in_silhouette: Reply From: crazymeow

For anyone who might encounter the same problem:

Quote from godot docs:

bool has_user_signal ( String signal ) const

Returns true if the given user-defined signal exists. Only signals added using add_user_signal are taken into account.

So you should use has_signal for statically defined signals.