A Comprehensive Guide to Using Animator Blend Tree in Unity3D
What is a BlendTree?
A blend tree is much like a normal animation transition. In an animation transition, you are going from one animation and transitioning into a different animation. A blend tree, however, allows the blending of animations together using variables. Blend trees are commonly used for things like character movement. With a blend tree, you can control the blending of animations using variables that you define. This allows you massive control over the look and feel of your animations.
How to Use BlendTree?
1. Import 3D model in unity. Here I am using a hand model in FBX format. And drag and drop that model into a Scene and set it according to your Game view.
2. Now, Create an Animation controller by right-clicking in the project window -> Create -> Animation Controller and name it as you want.
3. Now, select the Hand model from the hierarchy and add the component “Animator” and attach the animation controller to the controller field of the Animator Component.
4. Then, open the Animator window by clicking on Window -> Animation -> Animator where we can manage our animations.
5. After that, delete the current animation shown in an Animator window and create New BlendTree by right click in the Animator window -> create a new state -> from the new blend tree.
6. Now, Add parameters according to your requirements, here I am going to manage four animations for hand so I make two parameters called “Grip” and “Trigger” and then double click on the BlendTree option it will open a new window and select Blend type to “ 2D FreeForm Cartesian”.
7. Now Click on BlendTree in an Animator window and add Motions(animations) that you want to manage by BlendTree in the inspector window.
8. Here I add four animations as I wanted to manage four animations through this BlendTree. And select those two parameters in the parameter field on the top side of the Inspector Field.
9. After that, Create a new script by Right click in the project window -> Create -> C# script and named it as you want. And select the hand model in the hierarchy window and add that script in the inspector window. And open that script by double-clicking on that.
10. Now, in that script – Make a variable of Animator and get the reference of Animator in the Start function. And then make a function for play animation, in that function you have to pass the parameter name and value. Use that function for playing animation.
If you have any questions regarding Unity Game Development Connect with us today!