Unity - Iterate Animations in (legacy) Animation

Working with some old assets, I had to iterate through the Animations in the Animation component. Little did I know that what I was actually looking for was called Clips and these were contained in their own AnimationState.
Here is the code:


Animation _anim;
AnimationClip _originalClip;
Dictionary<int, AnimationClip> _animClipsMap = new Dictionary<int, AnimationClip>();

private void Start()
{
    _anim = GetComponent<Animation>();
    _originalClip = _anim.clip;
    int index = 0;

    foreach (AnimationState state in _anim)
    {
        _animClipsMap.Add(index, state.clip);
        index++;
    }
}


Comments