Animation keyframes

Is there a way to get keyframe information from an animation in code? I’m trying to obtain hip rotation from one animation that isn’t playing, and then apply it to the transform.

I’m using
https://docs.unity3d.com/ScriptReference/AnimationClip.SampleAnimation.html
right now.

I’m creating dummy hierarchy of bones with only bones I’m interested in and use it as a parameter to SampleAnimation.
After sampling I’m retrieving the Transfrom data.

2 Likes

Thanks for your reply. :slight_smile: I’m not at my dev computer right now so I can’t test. So I’d use SampleAnimation on the animation I want the hip rotation from, then apply that to the current animation. Does this update instantly so on the next line of code the rotation is applied or do I have to wait for a frame update or something? Does the animator kick back in after using SampleAnimation or do I have to resume it somehow?

You apply animation clip to Transforms than you copy result to another Transform.
Transforms are updated instantly.

Nothing kicks back, I’m not sure what you are talking about.

I realized what you were talking about after getting home and trying it out. I duplicated my model, made another animator controller for it, playing the same animations on both objects at the same time, taking the spine rotation from my ‘source’ (no upper body mask) and copying it to my ‘target’ (has upper body mask) so everything looks the way I want it to. It’s working pretty well. I’m going to add some animation rigging to even out the twist in the hips to spine.

My only issue is that some part of the source model needs to be rendered in order for this to work. How did you handle this?

Nothing needs to be rendered, remove or disable renderers from source.
What you need is bones structure only (and a root transform), and you don’t event need the whole skeleton.

If I disable all the skin mesh renderers then the animations don’t seem to play. As soon as I enable one of them the animations play.

I’m not much of a modeler, so I probably won’t be going the bones only route. Although, thinking about it, I could set up a game object with the right hierarchy, set up an avatar and do it that way instead of duplicating my target model. I’ll have to try some things when I get home.

I don’t suppose you have any tips for having to deal with two separate animation controllers?

Frankly speaking I’m not sure what you want to achieve anymore.

I wanted to transfer the spine rotation from one animation, to another. I am now doing that thanks to your help. :slight_smile: See this thread ( Animation mask for upper body and hip rotation ) to see the problem I had with trying to do separate upper body animations.