Simple question trying to change animations with AnimationPlayer

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

I have a very simple problem trying to change the animation based on a button I press.

Within my Node2d (SoldierRig) I have a few animations set on the AnimationPlayer. upon trying to simply change animations using the following command

func _on_TakeCoverButton_button_down():
$SoldierRig/AnimationPlayer.play = "Prone"

I expected the animation to change from “Running” to “Prone” but instead the game crashes and I get the error “Invalid set index ‘play’ (on base: ‘AnimationPlayer’) with value of type ‘String’.” Could someone please show me what’s wrong with my syntax?

:bust_in_silhouette: Reply From: Dlean Jeans

The correct syntax is:

$AnimationPlayer.play(animation_name)

or in your case:

func _on_TakeCoverButton_button_down():
  $SoldierRig/AnimationPlayer.play("Prone")

AnimationPlayer.play is a method, you call it with () not assign it with =.