1
\$\begingroup\$

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!

\$\endgroup\$
9
  • \$\begingroup\$ Have you taken a look at the functionality provided by the AnimationUtility class? \$\endgroup\$ – DMGregory Jun 8 at 20:58
  • \$\begingroup\$ @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? \$\endgroup\$ – tmighty Jun 8 at 21:01
  • \$\begingroup\$ 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? \$\endgroup\$ – DMGregory Jun 8 at 21:02
  • \$\begingroup\$ 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. \$\endgroup\$ – tmighty Jun 8 at 21:04
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – DMGregory Jun 8 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.