0 votes

When I use .play() It says " Invalid call. Nonexistent function 'play' in base 'GDNativeClass'."

func get_input():
var vy = velocity.y
velocity = Vector3()
if Input.is_action_pressed("move_forward"):
    velocity += transform.basis.z * speed
    anim.play("leg_movement")
if Input.is_action_pressed("move_backward"):
    velocity -= transform.basis.z * speed
    anim.play("leg_movement")
if Input.is_action_pressed("move_right"):
    velocity -= transform.basis.x * speed
    anim.play("leg_movement")
if Input.is_action_pressed("move_left"):
    velocity += transform.basis.x * speed
    anim.play("leg_movement")
asked May 26 in Engine by Reganazer (12 points)

You left out some code. What have you assigned to anim?

var anim = AnimationPlayer

2 Answers

0 votes

if you use gd script

you can use $AnimatedSprite.play("the name of your animation")

change AnimatedSprite by the name of your node

answered May 26 by sphixy011 (42 points)
0 votes

When you write

var anim = AnimationPlayer

You're assigning anim to the AnimationPlayer class. This is why you get an error.

What you want is to assign it to your specific animation player node. You can do this with get_node("AnimationPlayer") or the shortcut $AnimationPlayer. In addition, you need to make sure the node is ready first:

onready var anim = $AnimationPlayer
answered May 27 by kidscancode (16,966 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.