Godot Version
4.3
So, I have a area where, when the player enters, it instances 3 enemies and has a variable that ticks down with each one dead, at 0 left spawning a key to let the player leave. I am doing so by having the enemy emit a signal on death and having the area connect to the signal to trigger the function. Those all seem to work, but it never runs the function itself. Maybe I made a mistake with code? I’m not too sure and I’m a bit new to GDScript so maybe I missed something obvious.
Enemy Script:
func _on_hurtbox_area_entered(area: Area2D) -> void:
if area.is_in_group("Attacks"):
health_amount -= area.damage_amount
if area.get_parent().has_method("get_damage_amount"):
var node = area.get_parent() as Node
health_amount -= node.damage_amount
if health_amount <= 0:
enemy_killed.emit("enemy_killed")
var enemy_death_effect_instance = enemy_death_effect.instantiate() as Node2D
enemy_death_effect_instance.global_position = global_position
get_parent().add_child(enemy_death_effect_instance)
queue_free()
fight_start area script:
func fight_start():
if hasFightStarted == false:
hasFightStarted = true
collision_shape_2d.set_deferred("disabled", false)
for spawn_lightning in 3:
var lightning_ghost_instance = lightning_ghost.instantiate() as Node2D
if spawn_lightning == 0:
lightning_ghost_instance.position.x = 1360
lightning_ghost_instance.position.y = -96
elif spawn_lightning == 1:
lightning_ghost_instance.position.x = 1552
lightning_ghost_instance.position.y = -96
elif spawn_lightning == 2:
lightning_ghost_instance.position.x = 1456
lightning_ghost_instance.position.y = -160
get_parent().add_child(lightning_ghost_instance)
lightning_ghost_instance.connect("enemy_killed", Callable(self, "on_enemy_killed"))
await get_tree().create_timer(1.0).timeout
else:
return
func on_enemy_killed():
enemiesLeft -= 1
print("Enemies left:", enemiesLeft)
if enemiesLeft == 0:
player_camera_2d.limit_left = 32
player_camera_2d.limit_right = 2304
player_camera_2d.limit_top = -400
player_camera_2d.limit_bottom = 0
collision_shape_2d.set_deferred("disabled", true)
spawn_key()
Essentially I know that its not triggering the on_enemy_killed function because it’s debug message isnt playing. But earlier I had a debug message for both emitting the signal in the enemy and the connection being successful in the fight_start script. I have no idea why it’s not emitting correctly