My Enemy isn't dying, I need some help

Godot 4.3

Hello! I have made this enemy but for some reason it won’t die when it’s hit. The sounds will play but, nothing happens.

func _ready() -> void:
	max_value = 6
	min_value = 0
	value = 6

# Called when the node enters the scene tree for the first time.
func _on_radius_area_entered(area: Area2D) -> void:
	if area.is_in_group("Owie 1"):
		value -= 1
		$"../AudioStreamPlayer2D2".play()
	if area.is_in_group("Owie 2"):
		value -= 1
		$"../AudioStreamPlayer2D2".play()

	print(area.is_in_group("Owie 1")) # does this print anything?
	print(area.is_in_group("Owie 2")) # does this print anything?

	# check value here, as it's *after* the value has been changed
	if value <= 0: # make sure to check *less than* or equal to zero
		$"../death".play()

func _on_death_finished() -> void:
	get_parent().queue_free()

Are you sure that _on_death_finished() is actually hooked up to anything? Maybe stick a print() in there to see if it’s being called.

2 Likes

I have a print function, but it seems the sound “death” refuses to play at value 0, I’m not sure what to do here.

1 Like

Is $"../death".play() actually failing, or is it happening and not calling the callback?

1 Like

I do not see any code that waits for your death sound to finish playing. I think it is possible that you are calling queue_free too early.

I ran into that myself. This is how I fixed it:

if sounds.death.playing: await sounds.death.finished