Game Design Tutorial: How to Use Blend Trees in Unity

kristielGame Design & Development Tools, Tutorial, Unity Game Development

Game Design Tutorial: How to Use Blend Trees in Unity

Share this Post

In modern game design and development, 2D and 3D animations are increasingly complex. If you’ve worked on a game in any capacity, you have probably come across a need to have, for example, a walking animation trigger a running animation based on movement speed. To tackle such a problem, Unity 3D has something called blend trees. In this post, we’ll look at what blend trees are, why they are useful, and when to use them. I will also include a video tutorial that will go step-by-step and show you how to create a simple blend tree

What is a Blend Tree in Game Design?

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 blending 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.

A simple blend tree in Unity will look something like this:
Game Design Tutorial Simple Blend Tree

When to Use a Blend Tree

when to use a blend treeConsider the situation where you have a 3D model of a person. You want this model to run in whatever direction the player wants. Imagine your player is running forward, but also turning right at the same time. Using normal animation transitions, you run into a problem of figuring out whether you should be using the “run forward” animation or the “run right” animation. The result is that one animation is chosen over the other, resulting in a less realistic look. If you were to use a blend tree, you can tell Unity to blend the two animations together based on the direction the player is facing, for instance. With a blend tree, if the player is running forward and turning right at the same time, the animations for both “run forward” and “run right” will be blended together to make a seamless animation that looks more realistic.

While blend trees are great for locomotion, they may not be the best option for animations that are single actions or that loop. For instance, making a character jump may be a series of animations. However, there is a definite single animation for the start of the jump. After that, you would have a looping animation for the character while they are in the air. Lastly, you would have a single animation for the character landing. There’s really no need to blend these animations together like you would with normal movement. You could simply setup normal animation transitions that would allow you to go from the movement blend tree to the jumping animation.

What About 2D Game Design?

My tutorial video covers blend trees with 2D sprites and animations. Blend trees might seem like an odd choice for a 2D game since 2D animations are, usually, discrete and do not have the range of motion a 3D model might. However, blend trees are a great way to keep your animation state machine clean and simple. A normal animation state machine without a blend tree can get incredibly complex very quickly.

Consider this image of an animation state machine that handles 2D walking and idling in 4 directions without blend trees.

Game Design Tutorial: Messy State Machine

That is just for 8 animations. Sure, I could have taken more care to place my nodes better, but that doesn’t change the fact that we’ve already created a complex and tedious state machine with only 8 animations.

Compare that state machine to this:

Clean State Machine

This state machine uses two blend trees: Movement and Idle. The blend trees are decently complex, but handling transitions between walking and idling with this model is much easier. There are 2 transitions to deal with instead of the myriad transitions in the previous example. With this state, I have a single boolean that can dictate whether a tree is active or not. When a tree is active, the blend tree handles the animation states for me, based on the variables I’ve setup.

Blend trees allow you to keep your animations bundled together under a single node that is all controlled dynamically using variables. This makes it easier for you to manage transitions and the complexity of your animation state controller. This also applies to 3D animations. Blend trees, in general, are a great way to keep things organized and easy to use.

Game Design: Unity Blend Tree Tutorial

 Conclusion

Hopefully, this post has helped you better understand what blend trees are and how to use them. As usual, Unity offers fantastic tools to help make game development streamlined for you. Blend trees are just another wonderful tool in the toolbox. Good luck!

save moneyStudents, Teachers, and Schools: Save money on software, electronics, robotics, and more at Studica with academic discounts on a variety of technology products. Plus, Sign up for Studica’s email newsletter* and get a coupon code for even greater savings! *Currently, this newsletter is only available in the United States and Canada.

Blogger: Mark Philipp, Application Engineer at Studica

Share this Post