- Home /
Return the name of the animation clip playing
Hi, is there any way to return the currently playing animation clip, aside from creating a function which iterates through all the clips and testing each using animation.IsPlaying?
Cheers
Answer by flamy · Feb 02, 2012 at 03:19 PM
Hmm strange - I have an animation clip imported from max (maxClip) which I've split up into several clips. When I play the first clip, it plays what it should (that is a portion of the entire clip) but it still says that $$anonymous$$axClip is playing as opposed to section1 (the name of the clip I created from $$anonymous$$axClip). Any ideas? Thanks for the assistance. BTW the 'play automatically' box isn't ticked
sorry i never tried getting name when spliting the animation, dont have unity to try now either =/
Answer by juan-jo · Apr 12, 2020 at 11:47 AM
As of today it has been difficult for me to find conclusive information on this topic, so I'll try to help here:
With legacy animations, the playing clip name cannot be obtained. Indeed you have to iterate through all the clips and ask if they are playing or not.
I'll put here a simple tool and code sample. Is enough to attach it as a component to the same GameObject that has the Animation.
using UnityEngine;
public class inspector_animacion : MonoBehaviour
{
#if UNITY_EDITOR
Animation anim;
public string normalized_times;
[TextArea]
public string animaciones_en_play;
[Space]
public float time_scale = 0.3f;
public bool aplicar_time_scale;
void Start()
{
anim = GetComponent<Animation>();
}
void Update()
{
Time.timeScale = (aplicar_time_scale ? time_scale : 1);
normalized_times = animaciones_en_play = "";
foreach (AnimationState state in anim)
if(state.enabled)
{
normalized_times += state.normalizedTime + " ";
animaciones_en_play += state.name + "\n";
}
}
#endif
}
Your answer