Signal '' is already connected to given callable '' in that object

Godot Version

4.2

Question

So, now I am trying to use signals for the player and the enemy to “communicate” with each other when they are attacking each other, and run code for getting hurt accordingly. So far, everything works as intended, but I am getting an error that says this:

“Signal ‘’ is already connected to given callable ‘’ in that object.”

Where could the error come from? I understand that I am trying to connect signals twice, but I don’t understand how I could have done that. Any help would be much apreciated! thanks! :nerd_face:

A new error appears in console every time that enemy1 enters or exits the player’s hitbox, and every time the player enters or exits enemy1’s hitbox.

# ENEMY:
func enemy1() -> void:
	pass

func _on_area_3d_enemy_1_hitbox_body_entered(body):

# RANGE:
	if body . has_method ("player"):
		in_players_attack_range = true

# PLAYER ATTACK SIGNAL:
		body . do_attack_false . connect (not_being_attacked_enemy1)
		body . do_attack_true . connect (being_attacked_enemy1)

# EXIT HITBOX TIMER:
func _on_area_3d_enemy_1_hitbox_body_exited(body):
	if body . has_method ("player"):
		get_tree() . create_timer (exit_hitbox_time) .timeout . connect (exit_hitbox_timeout)
func exit_hitbox_timeout():
	in_players_attack_range = false
# PLAYER:
func player() -> void:
	pass
func _on_area_3d_player_hitbox_body_entered(body) -> void:
	if body . has_method("enemy1"):
		in_enemys_range = true

# ENEMY ATTACK SIGNAL:
		body . do_attack_enemy1_true . connect(being_attacked)

# EXIT HITBOX:
func _on_area_3d_player_hitbox_body_exited(body) -> void:
	if body . has_method("enemy1"):
		get_tree() . create_timer(exit_hitbox_time) .timeout . connect(exit_hitbox_timeout)
func exit_hitbox_timeout() -> void:
	in_enemys_range = false
func being_attacked():
	is_being_attacked = true
	get_tree() . create_timer(player_react_time) .timeout . connect(not_being_attacked)
func not_being_attacked():
	is_being_attacked = false

You never disconnect the signal, you need to do this if you want to connect it each time it enters

1 Like

I finally understand! thanks. I should use disconnect() at some point,

There is still a little problem: I had implemented a timer for the player to still be hit by enemies after fractions of a second after they had exited the enemy’s attack area, (so the enemies feel less stupid), but now as the signal is disconnect() inmediately when player exits area, the enemy does not attack even though the timer works perfectly. Having the disconnect after the timer makes the first error come back for some reason (I will update when is solved)

Here is how the code looks now, and the original error is completely fixed (#EXIT HITBOX now has the disconnect() function):

# ENEMY:
func enemy1() -> void:
	pass

#ENTER HITBOX:
func _on_area_3d_enemy_1_hitbox_body_entered(body):
	if body . has_method ("player"):
		in_players_attack_range = true

# PLAYER ATTACK SIGNAL:
		body . do_attack_false . connect (not_being_attacked_enemy1)
		body . do_attack_true . connect (being_attacked_enemy1)
func being_attacked_enemy1():
	is_being_attacked_enemy1 = true
func not_being_attacked_enemy1():
	is_being_attacked_enemy1 = false

# EXIT HITBOX:
func _on_area_3d_enemy_1_hitbox_body_exited(body):
	if body . has_method ("player"):
		body . do_attack_true . disconnect (being_attacked_enemy1)
		body . do_attack_false . disconnect (not_being_attacked_enemy1)
		get_tree() . create_timer (exit_hitbox_time) .timeout . connect (exit_hitbox_timeout)
func exit_hitbox_timeout():
	in_players_attack_range = false
# PLAYER:
func player() -> void:
	pass

# ENTER HITBOX:
func _on_area_3d_player_hitbox_body_entered(body) -> void:
	if body . has_method("enemy1"):
		in_enemys_range = true

# ENEMY ATTACK SIGNAL:
		body . do_attack_enemy1_true . connect (being_attacked)

# EXIT HITBOX:
func _on_area_3d_player_hitbox_body_exited(body) -> void:
	if body . has_method("enemy1"):
		body . do_attack_enemy1_true . disconnect (being_attacked)
		get_tree() . create_timer(exit_hitbox_time) .timeout . connect(exit_hitbox_timeout)
func exit_hitbox_timeout() -> void:
	in_enemys_range = false
func being_attacked():
	is_being_attacked = true
	get_tree() . create_timer(player_react_time) .timeout . connect(not_being_attacked)
func not_being_attacked():
	is_being_attacked = false