Animation is getting stuck in the first frame after spamming the input really fast

Godot Version

4.6

Question

Hello! I noticed that my animation gets stuck in one frame when I spam an Input and enter repeatedly into the same States, I am using an animation tree and an State Machine based on Nodes for the character animation. But when I spam an Input it get’s stuck in the first frame until it changes states. It happens with all of them, so I’m guessing that the problem is the same in all. Here is the code for the dashing forward state for example:

extends StateBaseChar
@onready var animation_tree: AnimationTree = $"../../Sprite3D/AnimationTree"
@warning_ignore("unused_parameter")




func on_process(delta):
	char.state_machine.travel("dash_f")
	char.velocity.x = char.DASHSPEED
	
	char.move_and_slide()
	animation_tree.animation_finished.connect(_on_AnimationPlayer_animation_finished)
	
	

func _on_AnimationPlayer_animation_finished(anim_name):
	
	
	match(anim_name):
		
		"dash_f":
			if Input.is_action_pressed("derecha"):
				state_machine.change_to("PlayerStateWalkf")
			elif Input.is_action_pressed("izquierda"):
				state_machine.change_to("PlayerStateWalkb")
			elif Input.is_action_pressed("agacharse"):
				state_machine.change_to("PlayerStateCrouch")
			else:
				state_machine.change_to("PlayerStateIdle")

I believe that I should check if the animation is already playing, but I’m not sure how to do it with how i’ve made the code so far, if any of you have an idea on how I could do it or another possible solution I would appreciate the help greatly

I fixed it by creating a new state between the DashF and Idle states and using start(“dash_f”) instead of travel(“dash_f”). I also now check in the dash state if it isn’t already in the current state. I’m not sure what’s the reason but I came to that solution by accident :man_shrugging:

Here is the new code for the dash:

extends StateBaseChar@onreadyonready var animation_tree: AnimationTree = $“../../Sprite3D/Animatio@onreadyTree”@onready var playback = animation_tree.get(“paramete@warning_ignores/playback”)@warning_ignore(“unused_parameter”)

func on_process(delta):

char.state_machine.start("dash_f")
char.velocity.x = char.DASHSPEED * char.axis
char.move_and_slide() 
state_machine.change_to("PlayerStateDashingF")

And here is the code for the state between the dash and the Idle, I called it dash@onreadyng:

extends StateBaseChar@onready var animation_tree: AnimationTree@onready= $“../../Sprite3D/AnimationTree”@onready var animation_playback = @warning_ignorenimation_tree.get(“parameters/playback”)@warning_ignore(“unused_parameter”)

func on_process(delta):

char.move_and_slide() 
animation_tree.animation_finished.connect(_on_AnimationPlayer_animation_finished)

func _on_AnimationPlayer_animation_finished(anim_name):

match(anim_name):
	
	"dash_f":
		if Input.is_action_pressed("derecha"):
			state_machine.change_to("PlayerStateWalkf")
		elif Input.is_action_pressed("izquierda"):
			state_machine.change_to("PlayerStateWalkb")
		elif Input.is_action_pressed("agacharse"):
			state_machine.change_to("PlayerStateCrouch")
		else:
			state_machine.change_to("PlayerStateIdle")

I’ll leave this here in case someone has the same problem that I had as a posible solution