0 votes

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?

in Engine by (15 points)

1 Answer

0 votes

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 =.

by (4,155 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.