How to call AnimationPlayer.Play() in C# Godot ?

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

Hello everyone;

I’m here to ask a question,
For begin, i’m beginner… so don’t judge me too harshly haha.

I follow a good Youtuber who “Make an action RPG in Godot 3.2” :
https://www.youtube.com/channel/UCrHQNOyU1q6BFEfkNq2CYMA

In the follow video, after creating few animation with “AnimationPlayer” like “RunRigh”, “IdleRigt”, “RunUp”…
He just set “animationPlayer” With $AnimationPlayer and after this, the line who do the animation is "animationPlayer.play(“RunRight”)

In my goDotproject, i have the same configuration as his:

But i really don’t understand how doig the same thing at him. I am trying to search on Internet and on this forum, but i didn’t found my answer.


(Sorry for my probably bad English)

Thank you in advance,
Xemnai

:bust_in_silhouette: Reply From: davidoc

You need to cast to AnimationPlayer the node you are getting:

((AnimationPlayer)GetNode("AnimationPlayer")).Play("RunRight");

or

var ap = GetNode("AnimationPlayer") as AnimationPlayer;
ap.Play("RunRight");

Thanks for your fast answer !

Xemnai | 2020-04-29 01:23

yo THANK YOU so much, I couldn’t find good information on this anywhere else

Mystical-TEDDY_ | 2022-02-19 17:57

1 Like