I’ve got a project with a very unusual need: I need to sample and mix AnimationClip frames, in essentially random order.
For example: I want to set my model to 10% of ClipA at frame 0 plus 90% of ClipB at frame 17. Or — also an acceptable alternative — 10% of ClipA at frame 0, plus 90% of whatever pose the model was previously in.
I know about AnimationClip.SampleAnimation, but it doesn’t support this sort of mixing. I’d be happy to apply all the bone rotations (in our animations there are only rotations, no scaling or translations) myself. But how do I get that data?
The only method I can think of, based on the docs, is to have an invisible avatar in the scene, SampleAnimation into that, and then read the rotations out of its transform hierarchy and apply them to my real model. That would work but seems a bit cumbersome. Is there any better method?
One hacky way that I know for getting this result is using the animator with two additive layers, where each has states with speed set to 0. You can then play those states at a given frame and sample/mix them by changing the weight of the layers. Example added as the attachement.
With this approach you can use as many layers as you like, at a cost of having to buffer some editor-only animator stuff before deploying. Other problem is that it hurts to not be able to create animator states from script at runtime.
Playables are also available, and they have blend trees which could be probably used in this case:
@Grizmu , this is a very cool trick. It took me a little while to fully grok it, but I believe I understand now.
But unless I’m mistaken, this relies on UnityEditor.Animations, and so can’t work in a build. I need something that works at runtime, not just in the editor.