- Home /
How To Get Current Animation Name
Hello Everyone
i'm trying to send Animation Throw RPC
but i have many Animation, so i will just try to make Shortcut way
.animation[CurrentAnimatinoName].speed = VlocityMagnitude / RunSpeed;
i want to get CurrentAnimatinoName. can anyone help me please?
Well everyone says you can't because there can be multiple animations playing at the same time etc. But in my case i have just one animation per state and found a neat way to get currently playing animation without doing all IsPlaying() loop thing. It's also precise. And i must state i'm doing this for legacy mode. Sorry if its too late and told before.
So you can call this once in start and add a specific event to each clip:
foreach (AnimationState state in animation)
{
AnimationEvent animationEvent = new AnimationEvent();
animationEvent.stringParameter = state.name;
animationEvent.functionName = "SetCurrentPlayingAnimation";
animationEvent.time = 0f;
animation[state.name].clip.AddEvent(animationEvent);
}
Thus every single beggining of your animation state you get the name of it. Then place method "SetCurrentPlayingAnimation(string statename)" in "yourclass" attached to your object (whatever it is) and you can set the result "state.name" to a property like currentState in it.
Answer by TonyLi · Apr 24, 2013 at 11:55 PM
There is no "current animation" because multiple animations can be playing at the same time. For example, you could be cross-fading between idle and run, or you could be playing a blend of walk animations (walk forward + strafe right) and also upper body animations such as waving, all at the same time.
I recommend keeping track of the animation yourself. For example:
string currentAnimation = null;
currentAnimation = "Run Forward";
animation.Play(currentAnimation);
animation[currentAnimation].speed = VelocityMagnitude / RunSpeed;
The code above is just an example based on your question that should get you started. But in practice you'll probably want to implement something more robust.
Another approach would be to iterate through all the clips in animation[] and examine the weights. Hmm, I just noticed these have both suggested earlier in this question: http://answers.unity3d.com/questions/153785/retrieving-the-name-of-the-animation-currently-pla.html
umm okey, so there is no way to Find the name of clip that already playing,
u know because i have allot of animation and i need to send them by RPC
so if i could found way to get the name will be allot easier,
anyway thanks
Answer by SgtOkiDoki · Aug 10, 2019 at 07:12 AM
I guess that's what you have been looking for.
private string CurrentPlayingAnimation
{
get
{
if (this.Animation.isPlaying)
foreach (AnimationState item in this.Animation)
if (this.Animation.IsPlaying(item.name))
return item.name;
return null;
}
}
Answer by Seb_GTB · Feb 17, 2021 at 04:38 PM
Mmmm I prefer...
Animator animator;
AnimatorClipInfo[] animatorinfo;
string current_animation;
void Awake()
{
animator = GetComponent<Animator>();
}
void Update()
{
animatorinfo = this.animator.GetCurrentAnimatorClipInfo(0);
current_animation = animatorinfo[0].clip.name;
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
The AnimationClip 'Attack' used by the Animation component 'Knife' must be marked as Legacy. 1 Answer
error CS0246 anybody help? 1 Answer
error CS0117: `Time' does not contain a definition for `deltaTime' 1 Answer
IndexOutOfRangeException: Array index is out of range 0 Answers