How to make Animation player start animation from the beginning when its called?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By LotusOrb

Im using a state machine and have anims for block attack and crouch. When I am crouching or blocking, and then press attack buttong while holding crouch or block still, the animation properly plays the animation from the start. However if I already holding attacking, and then then press block or crouch, when I let go, instead of returning to the beginning of the attack animation, it leaves off where it was interrupted by block or crouch.

Ive tried various different things like seek and clear queue but cant seem to find the solution im sure its not very complicated.

Different parts of my code, sorry if its not help, its super messy and hasnt been scrubbed of useless comments.

parent.attack_finished = false
parent.attack_timer.start()

		if parent.attack_points == 1:
			parent.anim_player.play("Attack2")
			 
		if parent.attack_points == 2:
			parent.anim_player.play("Attack1")

if ![states.wall_slide].has(state):
if event.is_action_pressed(“roll”) && ![ states.roll].has(state):
#later change air attack after method call slash
set_state(states.roll)
elif event.is_action_pressed(“attack”) && !parent.is_on_floor() && state != states.roll:
set_state(states.air_attack)
#check if on floor for block crouch and attack
elif parent.is_on_floor():
#checks if already holding attack buttong
if event.is_action_pressed(“attack”)&& !.has(state)&& parent.attack_finished == true:# && state != states.attack && parent.attack_finished == true:
parent.attack_timer.stop()
set_state(states.attack)

		elif event.is_action_pressed("block"):# && parent.attack_finished == true:
			set_state(states.block)
		elif event.is_action_pressed("down"):# && parent.attack_finished == true:
			set_state(states.crouch)

match state:
states.idle:
if !parent.is_on_floor():
if parent.velocity.y < 0:
return states.jump
else:
return states.fall
elif parent.velocity.x != 0:
return states.run
elif Input.is_action_pressed(“down”):
return states.crouch
elif Input.is_action_pressed(“block”):
return states.block
elif Input.is_action_pressed(“attack”):
return states.attack
states.run:
if !parent.is_on_floor():
if parent.velocity.y < 0:
return states.jump
else:
parent.coyote_timer.start()
return states.fall
elif parent.velocity.x == 0:
return states.idle

elif Input.is_action_pressed(“down”):

return states.crouch

elif Input.is_action_pressed(“block”):

return states.block

elif Input.is_action_pressed(“attack”):

return states.attack

	states.jump:
		if parent.wall_direction != 0 && parent.wall_slide_cooldown.is_stopped():
			return states.wall_slide
		elif parent.is_on_floor(): 
			return states.idle
		elif parent.velocity.y >= 0:
			return states.fall
	states.fall:
		if parent.wall_direction != 0 && parent.wall_slide_cooldown.is_stopped():
			return states.wall_slide

elif parent.is_on_floor() && parent.velocity.y >= 280:

return states.dodge

		elif parent.velocity.y < 0:
			return states.jump
		elif parent.is_on_floor():
			return states.idle
	states.wall_slide:
		if parent.is_on_floor():
			return states.idle
		
		elif parent.wall_direction == 0:
			return states.fall
	states.block:
		if !Input.is_action_pressed("block"):# || Input.is_action_just_released("block")
			return states.idle
		elif !parent.is_on_floor():
			if parent.velocity.y < 0:
				return states.jump
			else:
				return states.fall

elif Input.is_action_pressed(“block”) && Input.is_action_just_pressed(“attack”):

return states.attack

	states.roll:
		if parent.roll_finished == true:
			if Input.is_action_pressed("down"):
				return states.crouch
			if !parent.is_on_floor():
				if parent.velocity.y < 0:
					return states.jump
				else:
					return states.fall

			elif parent.velocity.x != 0 && !Input.is_action_pressed("down") || !Input.is_action_pressed("block"):
				return states.run
			elif parent.velocity.x == 0 && !Input.is_action_pressed("down") || !Input.is_action_pressed("block"):# && state != states.crouch:
				return states.idle
			
		
	states.crouch:
		
		if !Input.is_action_pressed("down"):# && parent.attack_finished == true:

if Input.is_action_pressed(“attack”):

return states.attack

else:

				return states.idle
		elif !parent.is_on_floor():
			if parent.velocity.y < 0:
				return states.jump
			else:
				return states.fall

elif Input.is_action_pressed(“down”) && Input.is_action_pressed(“attack”):

return states.crouch

elif Input.is_action_pressed(“down”) && Input.is_action_just_pressed(“roll”):

else:

return states.crouch

elif Input.is_action_pressed(“down”) && Input.is_action_just_pressed(“roll”):

return states.dodge

parent.move_speed = parent.move_speed * parent.roll_speed

elif Input.is_action_pressed(“jump”):

return states.jump

elif Input.is_action_pressed(“attack”):

return states.attack

	states.attack:
		
		if parent.attack_finished == true:#parent.attack_timer.is_stopped():
			if !Input.is_action_pressed("attack"):
				parent.is_attacking = false
				return states.idle
			elif !parent.is_on_floor():
				if parent.velocity.y < 0:
					return states.jump
				else:
					return states.fall

elif Input.is_action_pressed(“attack”) && Input.is_action_pressed(“down”):

return states.crouch

elif Input.is_action_pressed(“down”):

return states.crouch

elif Input.is_action_pressed(“block”) && Input.is_action_pressed(“attack”):

return states.block

elif Input.is_action_just_released(“down”):

return states.attack

elif Input.is_action_pressed(“block”):

return states.block

if Input.is_action_just_pressed(“block”) || Input.is_action_just_pressed(“crouch”):

parent.anim_player.stop(false)

elif Input.is_action_pressed(“down”):

return states.crouch

			else:
				return states.attack
:bust_in_silhouette: Reply From: Reloecc

Hello, I am not going to read this mess, but isn’t just the anim_player.stop(true) what you are looking for? That “true” is there for the “reset”. So stop should be placed prior the crouch animation call.