How to connect signals to enemies that not on the level yet?

Godot Version

4.2.1 Stable Mono


I’m having difficulty on connecting signal to enemies that not yet on the scene.

this is the reticle code:

func _on_area_entered(area):
	for body in get_overlapping_areas():
		if body.is_in_group("Enemy") && Input.is_action_pressed("FireButton") && weaponCooldown.is_stopped():
			emit_signal("TakeDamages", currentWeaponDamage)

this is the enemy code:

extends Node

signal TakeDamages
var enemyHP: int = 5

func TakingDamage(damage):
	enemyHP -= damage
	print("HP left: ", enemyHP)

func _on_reticle_take_damages(damageAmount):

I don’t remember where the _on_reticle_take_damages() came from, but it doesn’t have the green arow&square icon.

Also there’s an error that said: can’t emit non existing signal “TakeDamages”. But I’m guessing that’s because I haven’t connect the signal yet.

There’s no reason to use signals in this case. You can just do


Signals can be emitted even if they’re not connected. You’re getting an error message, because the signal doesn’t exist in the reticle class.

1 Like

That worked. Thanks a lot!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.