• Unity
  • Bone transform for a particular animation frame

Hi!
Is it possible to get bone transform for a particular animation frame?
I tried something like that but it give me wrong transform

TranslateTimeline translateTimeline = timeline as TranslateTimeline;
 if (translateTimeline == null)
 {
     continue;
 }



 foreach (var frame in translateTimeline.Frames)
 {
     float x = 0;
     float y = 0;
     translateTimeline.GetCurveValue(out x, out y, frame);
  
}
Related Discussions
...
  • Изменено

You can use IBoneTimeline.BoneIndex to get the bone index that the IBoneTimeline subclass (such as TranslateTimeline) affects.

BTW: your code does not show the relevant code sections that are accessing anything bone related.

Your definition of "bone transform for a particular animation frame" might be problematic depending on what exactly you want, as an animation either has a timeline that modifies a certain bone after a certain timepoint, or it does not modify it at all.

You said bone transform, but only seem to care about translation. A little pedantic, but the transform consists of translation, rotation, scale, and shear. Also a bone has both a local and a world transform.

Other things can affect bone transform besides a translate timeline, such as translate X/Y timelines or constraints.

If you want the bone's local transform and don't care about constraints, you could find the translate, translateX, and/or translateY timelines and apply it. The easier thing to do would be to pose the whole skeleton for a particular frame using Animation apply, then access the bone local transform (eg Bone x).

If you want the bone world transform OR you want the bone local transform and care about constraints, you'd need to call Animation apply then Skeleton updateWorldTransform, then access the bone's world transform (eg Bone worldX) or applied local transform (eg Bone aX).