My death animation doesnt play

Godot Version

4.2.1

Question

func death():
	if not global.player_alive:
		return
	if global.health <= 0:
		$AnimatedSprite2D.play("death")
		self.queue_free()

this is my code but my character just disappear (I tried delet self.queue command but it didnt solve it )

You need to wait until death animation finishes playing before calling queue_free().

Currently you just say AnimationPlayer to play a certain animation, but then immediately delete the whole object.

how can I do it

I set animation.finished func but my animation didnt play

I propose you to take an experiment. Remove queue_free() at all or use Timer. I think this will provide you a possibility to understand if the early call of queue_free() is the reason for the issue or not.

Best thing I have found for myself is using this: “Await get_tree().create_timer(1.0).timeout”.
Replace 1.0 in the create_timer part with whatever suits your needs, it’s in seconds.
That way, your animation will have time to finish, and you will control at what time you want other events to start, like a death message pop up or a menu, anything really.

just add

await $AnimatedSprite2D.animation_finished

before queue_free()

func death():
	if not global.player_alive:
		return
	if global.health <= 0:
		$AnimatedSprite2D.play("death")
		await $AnimatedSprite2D.animation_finished
		self.queue_free()

I made a func for wait but my animation doesnt play my problem isnt timer my problem is animation


I made animation finished func but my animation didnt play just first frame playing and freeze