How can I use Blend Trees to blend animations at random?


I’d like to know if it is possible and how should I proceed to blend smaller animations into the main ones randomly.

The project of the character in question, for instance, has a characteristic where his muscles twitch randonmly.

What I’d like to do is to create small animations for each of his limbs shaking, and then blend them at random while he is walking or idling.

I know I’ll have to create a script to control this randomness, but I have no idea on how to proceed with the blend trees. If it is even possible to do it this way.

Can you enlighten me on where I need to start?

The best would probably be to use additive animation layers.

Have the twitch animations in their own layer, and set it to be additive. Have that layer play an empty animation most of the time, and then blend it into the twitches at random intervals. That’ll give you the effect without making your main animator controller messy. Note that there’s some things that are not intuitive about additive animations, see here.

An alternative would be to have the twitches controlled by blend shapes, and then animate those randomly outside of the animator controller. Blend shapes are a bit clunky to work with, but it’s doable. You get/set the blend shape weights with SkinnedMeshRenderer.Get/SetBlendShapeWeight, and find the count and names with Mesh.blendShapeCount and GetBlendShapeName.