Is there any way to check if a node already has a signal connected?

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

i have this script to make a list of player’s unit and enemy’s unit, every time a unit is spawn or destroyed this function run again to update the list and reconnect the signals but…

func set_targets()-> void:
var nodos:Array = get_children() 
player_units.clear()
enemy_units.clear()
for element in nodos:
	if element.is_in_group("player"):
		player_units.push_front(element)
		element.connect("player_unit_destroyed",self,"handle_destroy_unit")
	if element.is_in_group("enemy"):
		lvl_top_score += element.score
		enemy_units.push_front(element)
		element.connect("enemy_unit_destroyed",self,"handle_destroy_enemy")
for element in player_units:
	element.set_targets_to_attack(enemy_units.duplicate(true))

i keep getting this error:

E 0:00:27.932   connect: Signal 'enemy_unit_destroyed' is already connected to given method 'handle_destroy_enemy' in that object.

<Error de C++>Method failed. Returning: ERR_INVALID_PARAMETER
<Fuente C++> core/object.cpp:1512 @ connect()
dev_lvl_combat.gd:55 @ set_targets()
dev_lvl_1.gd:111 @ _on_Timer_2_timeout()

so i want to check if they are already connected. But i don’t find the way.

-.-U !!! Sory: i just found it, the function is:

bool is_connected(signal: String, target: Object, method: String) const

“Returns true if a connection exists for a given signal, target, and method.”

i will leave this question for anyone else looking for this, (i didn’t find anything when i was looking for it)

andresTapa | 2021-11-17 13:28

2 Likes

thanks