Struggling with AnimationPlayer2D not playing the animation consistently

Godot Version

v4.2.2.stable.official [15073afe3]

Question

I’m very new at Godot so I hope I’m missing something simple. I’m struggling with an AnimatorPlayer2D node. I have a player character that gets knocked back and is supposed to “flash” (opacity adjusted back and forth). When I run this in game it works right the first time. Every time after the first time, however, it either doesn’t flash or the flash looks very different. I do have a Reset animation, although I’ve tested with and without the Reset animation and it doesn’t seem to affect this behavior. It seems like even though I tell the animation to stop, when it does the animation again it always feels like a different speed or starts in a different part of the animation.

I am also using timers to start and stop this. Any help or ideas are appreciated. I’m pretty lost with why the same animation would play differently each time.

Relevant script:

(in the get hit function:
player_animator.play("flash")
print("Current animation float on start: " + str(player_animator.get_current_animation_position()))

func _on_knockback_timeout():
	if hit:
		canmove = true
		swordactive = false
		hit = false
		hitstun_timer.start()

func _on_hitstun_timeout():
	if hitstun:
		hitstun = false
		print("Current animation float on stop: " + str(player_animator.get_current_animation_position()))
		player_animator.stop()

Output trying to measure when the animation float starts and stops:
Current animation float on start: 0
Current animation float on stop: 0.15000000596046
Current animation float on start: 0
Current animation float on stop: 0.049957
Current animation float on start: 0
Current animation float on stop: 0.15000000596046
Current animation float on start: 0
Current animation float on stop: 0.03333333333333
Current animation float on start: 0
Current animation float on stop: 0.08333333333333
Current animation float on start: 0
Current animation float on stop: 0.15000000596046

You should add a cooldown after the hit of player, not hard, you can do it by a timer but if you want that the damage flash must be equal to cooldown, then just add this line at the start of hit function:

if player_animator.is_playing(): return

And do not need to stop the animation in that hitstun timer timeout.