How to make an animation play only after another animation finished playing?

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

If the player holds down the left mouse button, a box is on the screen. If you press T while holding down the right mouse button, an animation plays (the box makes a 360 turn). My only problem is that if I press T and release the left mouse button while the (360 turn) animation is playing, the box stays on the screen after the animation ends. Also the box has an appearing and disappearing animation. The code:

if Input.is_action_just_pressed("left_mouse_button"):"appear")

if Input.is_action_just_released("left_mouse_button"):"disappear")

if Input.is_action_just_pressed("T") and Input.is_action_pressed("left_mouse_button"):"360turn")

Basicly it should be like: the player releases the left mouse button while the animation playing, after the 360 turn animation finished, the disappear animation plays or something like this, couldn’t really figure it out.

:bust_in_silhouette: Reply From: Death of Shadows

You could connect the animation player “animation_finished” signal to the box. When the animation player finishes an animation, check if the animation was “360turn”. Then, you can check whether or not the left mouse button is pressed and run the disappear animation if necessary.

func on_AnimationPlayer_animation_finished(anim_name:String):
    if anim_name == "360turn" and not Input.is_action_pressed("left_mouse_button"):"disappear")
:bust_in_silhouette: Reply From: grahamgodot

Hey, I struggled with this while processing turn animation for a robot to turn around before walking. This is working for me as of today, Godot 4.0.2:

# Have an array of your animation names to play (turns)
for turn in turns:
    # Start the animation player with the first animation
    if turn == turns[0]:
    # Queue the remaining animations
# Wait for all animations in queue to complete
await animation_player.animation_finished

This is not clearly documented, so I approached it incorrectly as treating the queue as an array that I would iterate over and play like this:

# Incorrect
for animation_name in animation_player.get_queue():

Wrong. You need to:

  • Start the animation player
  • Use animation_player.queue(animation_name)

It’s very simple once you wrap your head around this, just wasn’t clearly explained how to do it. The .get_queue() method actually worked for me sometimes but was buggy and jumped animations or would only play the last one which made it more confusing.