AnimationPlayer delayed by a frame

Godot Version

4.5.1

Question

When calling the Animation player’s play() command, it doesn’t seem to actually start playing until the frame after it’s called, causing a desync between what is supposed to happen and when it happens

My code looks like this:

func set_state(new_state):
	delete_hitboxes() #remove errant hitboxes
	state = new_state #set the state to the new state
	state_timer = 0 #reset the state timer
    play_animations() #play the animation

func play_animations():
	if state == Idle: #if the player is idle
		$AnimationPlayer.play("Idle") #play the idle animation
	elif state in [Attack_Ground, Attack_Air]: #if the player is attacking
		if attack.name == "5A": #if they're doing the attack 5A
			$AnimationPlayer.play("5A") # play the "5A" animation

and whenever I press the button to do the 5A attack, the state immediately gets set but it takes an extra frame for the animation to actually start

I don’t see anything wrong with the code. Maybe the animation’s frames are at the wrong positions?

if it makes a difference I’m calling set_state() in physiics_process but trying to call play_animations() in _process didn’t seem to change anything

I have all my animations to start at time 0, so I don’t think this is the case

it seems like the animation is starting on the correct frame but it isn’t actually updating anything until the next frame

ok so I figured out something that fixes it: turning the animationplayer’s callback mode from idle to physics seems to immediately update the animation to the proper first frame

1 Like