Blender Rigged Animations in Unity

Sharing is caring:

Want to learn how to use Blender animations in Unity?

In this Unity tutorial we’ll be going over how we can import our rigged model with animations from Blender into Unity. We’ll be exporting an FBX file from Blender then importing that file along with its textures into Unity. We’ll then take a look at how to prepare your mesh by taking a look at the import, rig and animation settings. For this mesh we created three animations back to back so we’ll be going into the animation editor to create three separate animation clips.

 

Import Settings

To start off you want to make sure you export the mesh from Blender using the Autodesk FBX file format. Unity will allow us to import this FBX file directly into the project. When you import the mesh you should be able to open up the prefab in the project panel and see an animation clip. This animation clip contains the three back to back animation clips we created in Blender.

Before we get into the animations, we’ll need to ensure our mesh is properly setup. Select the import tab from the inspector panel, then ensure the scale factor is set to 1. By default Unity likes to import the mesh with a scale factor of .01. Make sure you hit apply at the bottom of this menu. The second tab is called rig, select this tab and you’ll have a couple of drop down menus.

The first is the animation type and you’ll want to ensure this is set to generic. Generic is used for meshes that contain a rig but don’t conform the traditional skeletal rig that you might find on a full humanoid rig. Since our rig just contains a pair of arms our rig would be a generic rig. This should be generic by default, but if it isn’t then select it and hit apply at the bottom to ensure it is saved.

 

Editing Animation Clips

Now lets take a look at our animations. Click on the animations tab and you should now see a new menu that contains our animation, along with the preview window below to preview our animations. In the Clips section you should see one animation clip. We’re going to be making three separate clips from this so click the plus (+) icon in the bottom of the clips section twice in order to create two more clips.

Select the first animation clip in this list and rename it to wield. This will be our starting animation, so we’ll first set clamp animations if need be then you can enter the length of the animation in frames. You should see a Start and End slot and you’ll want to enter 0 and 10 for the frames. This will set the animation to start at frame 0 and end at frame 10.

The second animation clip will be called Slash and this will be our attacking animations. Make sure your select animation clip is selected in the list before making any changed. The start and end frames for this one will be 10 and 35. Finally our last animation clip will be called Idle and this will be our default animation when we’re not moving. This clip will be from 35 to 46.

 

Mecanim Setup

Now we can get into creating our Mecanim capabilities. To start we’ll need to create an Animator Controller, so in the project panel you want to right-click and select Animator Controller. Rename the controller Anim and we’ll add this to the mesh. To do this you’ll need to drag the mesh into the scene.

Select it from the hierarchy and in the inspector panel you should see the Animator component applied. In the Controller slot you’ll drag and drop the Animator controller that we’ve created. This will ensure that our mesh has the animator controller ready to go. Double click the Animator controller and you should see a new tab open up next to your Game and Scene windows called Animator.

In this window we’ll be adding our Animation States.  Drag in all three of the animation clips into this animator window. Make sure you’re selecting the actual animation clips from the project panel. By default the first animation you drag in will turn Orange which indicates it is the default animation clip that will play when we start our game.

The default animation for our character will be the Wield animation clip. So if you need to change the default clip, right-click on the state in the animator window then select Set as Default. If you play the game right now the Wield animation clip should play automatically.

Now we need to create transitions between our different animation clips. So right-click on the Wield animation and select Make Transition. You should see an arrow attached to the animation state.

With this arrow you’ll want to click on the Idle animation clip to create a transition. Then do the same thing from the Idle to Slash. Then once more going from Slash back to Idle. So now if you play the game you should see the transitions coming in and out. It should go from Wield to Idle to Slash and back to Idle where it should continue to loop through the transitions between Idle and Slash.

Right now we’re using the Exit Time condition for this parameter which means the transitions happen once they have finished playing the current animation. We need to change this using a Parameter.

To create a parameter you’ll notice a small drop down menu at the bottom left of the animator window called Parameters. Click the plus icon (+) and select Bool. This creates a Bool variable that we can then use in a script.

We’ll need to add this to the conditions under the transitions between Idle and Slash. Select the transition arrow going from Idle to Slash and now if you select the conditions the Slash Parameter should be available.

Select this parameter and ensure it’s using True. What this is doing is saying that in order for us to transition from Idle to the Slash animation our Bool Parameter must be set to True.

Now do the same thing for the conditions going from Slash to Idle, but instead of replacing the current condition you’ll just want to add in another one. So this should have two conditions.

You should have both Exit Time and  Slash Parameters for the conditions. To add a second parameter just click the plus icon (+) in the bottom right of this section. The Slash Parameter should be set to False.

Now all you need to do is add the script below to the mesh and you should have a slashing animation that plays when we press our left-click button (Fire1).

 

C# Script

AnimController.CS (Add this to the mesh)


using UnityEngine;
using System.Collections;

public class animController : MonoBehaviour {

	private Animator anim;

	// Use this for initialization
	void Start ()
               {
		 anim = GetComponent<Animator> ();
	        }

	// Update is called once per frame
	void Update () {

		if (Input.GetButtonDown("Fire1"))
		   {
		     anim.SetBool ("slash", true);
		   }
		else
		   {
		      anim.SetBool ("slash", false);
		   }

	}
}

Jonathan Gonzalez

I love all things in game development and want to contribute by teaching others how to create games. I'm always looking to help others create awesome digital worlds. I've been a hardcore gamer since I was a kid and now it's my turn to create awesome digital experiences.

More Posts - Website

Follow Me:
TwitterYouTube

Comments

  1. What did you do in Blender to keep the knife in the hand? I’ve tried the method here to no avail.

  2. Thanks

Trackbacks

Speak Your Mind

*