# How do I iterate through keyframes in an animation clip?

I have an animation clip that animates a complex model.

I would like to ask if it is possible to iterate through all bones and their key frames like that:

(pseudo code)

 foreach( GameObject obj in objects)
{
//get animation
Animation anim = obj.GetComponent<Animation>();

//some how get the keyframes
Keyframes[] keys = anim.???

Vector3 trans = keys[0].transform.localPosition;
Quaternion rot = keys[0].transform.localRotation;
}


I have copied this question from here because it resembles just the very same question but didn't yield an answer.

Thank you!

• Have you taken a look at the functionality provided by the AnimationUtility class? – DMGregory Jun 8 at 20:58
• @DMGregory No, I am currently stuck at the fact that animationclip.events.Length is always 0. So it doesn't seem to be possible to access the animation clip events directly, and that is why you pointed me to the AnimationUtility class? – tmighty Jun 8 at 21:01
• Your question does not ask about animation events. Is that what you want, instead of float curves like position x/y/z? This question also looks quite related to your previous one. Would you like users to focus on giving you answers to that one instead? – DMGregory Jun 8 at 21:02
• I don't think that I actually mean "events". The only thing that I could get from an AnimationClip were the ".events", so I thought these would be the keyframes that I'm after. – tmighty Jun 8 at 21:04
• They are not, as the documentation shows. AnimationEvents are callbacks where the animation invokes a function in your script when it reaches a particular frame. The AnimationUtility class gives you methods to get the float curves of an animation and iterate over/adjust its keyframes. – DMGregory Jun 8 at 21:06