Hit and death animation is not playing.

Godot Version

` 4.3

Question

My death and hit animation is not playing. I have setup the animated sprite in the inspector and also have the animations created. The other animations like run, idle, jump are playing properly. can someone help.

class_name DamageComponent
extends Node

@export var anim_sprite: AnimatedSprite2D

var health: int = 500

func _on_damage_to_player(amount: int) → void:
take_damage(amount)

func take_damage(amount: int) → void:
print(“Damage dealt”)
anim_sprite.play(“hit”) # Play the hit animation
health -= amount
if health <= 0:
die()

func die() → void:
print (“Player Died”)
anim_sprite.play(“death”)
anim_sprite.animation_finished.connect(_on_die_animation_finished)

func _on_die_animation_finished() → void:
if anim_sprite.animation == “death”:
call_deferred(“reload_scene”)

func reload_scene() → void:
get_tree().reload_current_scene()

Probably playing the other animations every frame, so they overwrite the death/hit animation. You need to prevent other animations from playing over these death and hit animations.