AnimatedSprite2D won't play, while others do

Godot Version

3.6.2

Question

I am trying to create an attack using AnimatedSprite2D. The code I have for it is the same as with my movement inputs, which do play their animations, except for the addition of an AnimationPlayer, which I’m using to add a hitbox to the animation itself.

onready var attack_coll = $AttackColl

onready var _animated_sprite = $AnimatedSprite
onready var animation_player = $AnimationPlayer




func _physics_process(_delta):
	
	if Input.is_action_just_pressed("e"):
		_animated_sprite.play("Attack")
		animation_player.play("attack")
		print("attack")
	#movement

	if Input.is_action_pressed("ui_left"):
		_animated_sprite.play("Walk")
		velocity.x -= move_speed

	elif Input.is_action_pressed("ui_right"):
		velocity.x += move_speed

		_animated_sprite.play("Walk")
	else:
		_animated_sprite.play("Idle")

Your capitalization is different in the two nodes. Are you sure it’s not supposed to be attack instead of Attack?

Yes, I know I should probably name them differently but Attack refers to the animation, while attack refers to the hitbox associated with it

If you logically step through this function line by line it may be more apparent that _animated_sprite.play("Attack") will never finish the animation.

If the player just pressed action “e” attack will begin to play

But then it is interrupted by either “Walk” or “Idle”, which is .played every frame.

Thank you! This actually quite helped, I managed to create what is.. very likely a hacky solution by making a timer node and in the code
var timerOff = false
onready var timer = $Timer

func _on_Timer_timeout():
timerOff = false
pass # Replace with function body.

func _physics_process(_delta):

if Input.is_action_just_pressed("e"):
	timerOff = true
	$Timer.start(0.5)
	_animated_sprite.play("Attack")
	animation_player.play("attack")
	print("attack")
	
#movement

if Input.is_action_pressed("ui_left"):
	_animated_sprite.play("Walk")
	velocity.x -= move_speed

elif Input.is_action_pressed("ui_right"):
	velocity.x += move_speed

	_animated_sprite.play("Walk")
elif timerOff == false:
	_animated_sprite.play("Idle")