Introduction to Characters and Animation in Unity
If you’ve wanted to add characters and animation to your game, or got stuck on a problem with them in the past, let me show you how to get past some of the most common problems people run into. It felt like it took me forever to get past the problems I saw, so let me guide you through this. By the end of this article, you will have a character in your scene, looking and acting like you want it to.
The only prerequisites are:
First, have a scene ready in Unity. Let’s keep it simple. I will just add a plane:
Note that I am oriented so that the Z axis, which points in the forward direction, is pointing toward me. I did this because when we bring the character into the scene later on, we will be able to see the front of the character.
I am using the Universal Render Pipeline because it will trip us up a little, and I can show you how to account for this.
Second, have an account on Mixamo.com. It’s free.
Getting our Character
Once you get logged in, click on Characters at the top of the page, and search for Survivor. Here is our dude:
Be sure you choose this character. He has problems we need to fix.
When you select this guy, he shows up in the panel to the right in Mixamo:
Right now this character is in the T pose, which is a default pose for animation.
You can read more about the T pose at https://en.wikipedia.org/wiki/T-pose
We could just download our character right now, but we want to add an animation and download the whole package for testing purposes. For now, let’s just be boring and choose an idle animation. You do that by clicking on Animations and searching for idle.
I chose Breathing Idle, because it has enough movement to be obvious, but is boring enough that you’ll want to replace it later:
When you choose an animation, your character will drop out of the T pose and animate:
OK, he’s not animating because I didn’t bother with a video capture.
Time to download our character. Click on the download button, and change the Format to FBX for Unity (.fbx):
Make sure you leave With Skin selected, and Click Download:
Usually, the file name will be in the format charactername @ animationname, but not always. Don’t worry about it if you end up with some strange name like Ch17_nonPBR. You will still have the right character.
Drag your downloaded file into Assets, and create an empty folder next to it called exported, or something appropriate for some items you are about to export:
Now open the prefab and take a look inside:
Different characters will have different contents, but the main thing to note is the Hips prefab mixamo, or …). This is the animation rig. Breathing Idle is the animation.
Select the top level prefab of the character:
and drag it into your scene:
We need to fix the materials on this guy. Easy enough to do, but note that the materials are inside the prefab — and you can’t change them from there.
Fixing Materials
Now we will use that ‘exported’ folder we made earlier:
Select the prefab in Assets, and in the Inspector, select the Materials tab
Click Extract Textures…, and choose the new ‘exported’ folder. Most likely, you will get this popup about NormalMap settings:
Click Fix now.
OK, the character looks better, but:
He is see-through.
Now click Extract Materials… and extract them to the same ‘exported’ directory. No change, still see-through.
In Assets, go into the exported directory, and click on the material:
Note the Transparent Surface Type setting in the inspector:
Set it to Opaque, and now the character looks better…
At least he’s no longer transparent.
There is some weird gray stuff going on. Take a look at his head:
With the material still selected, you will see the same gray artifacts in the material preview:
To fix this, note that the Surface Input/Source is set to Metallic Alpha:
Set it to Albedo Alpha, and now the head looks somewhat better, but not perfect:
Rotate around a little and get a good look at his oh-so-fabulous hair from another angle:
Not quite right. It looks like he is using proper hair gel, but I think he uses too much conditioner. Select the material again and set the Render Face to Both, and look again:
Better. Strange looking, but better. Rotate around the character a little bit to make sure he is OK.
If you change the Workflow Mode from Metallic to Specular, note the differences in the material preview window. The changes are subtle for this character, so use whichever you like.
This is all I found “wrong” with this character, and this is why I chose him for this article. There are characters on Mixamo from all kinds of sources, and some of them are in much better shape than this guy right out of the box.
Animating the Character
We downloaded an animation, so let’s use it. If you click Play, nothing will happen.
If you click on the character prefab in the hierarchy, you will just see a transform.
Down in Assets, get out of the ‘exported’ folder, select the character, and in the inspector, click on Rig:
Set Animation Type to Humanoid, and leave Avatar Definition at Create From This Model.
Click Apply. Do not forget to do this!
Don’t bother clicking Play just yet, because nothing will happen. Click on the player prefab in the hierarchy again, and you will see that he has an Animator component, but no controller:
Go into Assets, right-click, select Create/Animator Controller, and name it appropriately:
Drag that into the Controller slot on the character in the hierarchy.
Now if you click Play, we get something:
Not what we want, but we did get something. Go ahead and stop playing. In Assets, select the character again, and click the Animation tab. Scroll down a bit until you see the animation name:
Check the Loop time checkbox, and hit Apply again. Do not forget that.
Open the prefab down in Assets, and then double-click the Survivor Animator Controller. The Animator Window should open:
Now drag the Breathing Idle animation, found inside the prefab, into the palette:
It will automatically get set as the default animation.
Now go back to the scene, and press play again. This time our character stays standing up, and is idling like we want him to:
Congrats! You have an animated character that looks, er, nice? And he is idling. And he isn’t sinking into the floor like he is on quicksand.
Adding Other Animations
It’s a start. But a zombie like this should be as happy as YOU are. Let’s make him dance. Go back to Mixamo.com, click in the search window, and choose Dance:
Clear the word idle out if it’s still there, and you should get lots of dances to choose from.
I have to go with Thriller Part 3. Now click Download, and this time, turn off the Skin:
Make sure you have the Format set as FBX for Unity(.fbx), and click Download.
This download will be a lot smaller, since it is just the animation without the skin:
Drag this one into Assets next to the previous one, and open it up:
You might be tempted to drag this animation onto the Animator Controller and replace Breathing Idle with this one.
You know what? This won’t take long. If you do that:
and you press Play, this is what you get:
We’re back to quicksand because our new animation doesn’t know how to control our character. Even though our character was selected in Mixamo. This drove me nuts until I figured out what was going on.
Stop playing, delete the animation from the Animator Controller palette, and let’s fix this.
Select the new prefab down in Assets:
In the inspector, select Rig:
We need to set Animation Type to Humanoid again, but we already have an Avatar — we have survivor_2_lusth @ BreathingIdleAvatar in the previous prefab. So in Avatar Definition, select Copy From Other Avatar, and we get a source field. Click the activator to the right of the field and select our avatar from earlier:
Click Apply. Seriously, if you forget that, it can take a while to figure out what went wrong.
Now our thriller animation is set up.
This is optional, but just to show you that you can do this, select the Thriller Part 3 animation and click ctrl-D to duplicate it outside of the prefab:
We’re done with the new prefab, so go ahead and delete it:
This will keep your Assets folder cleaner, but is probably not the way forward if you need to change the animation/avatar combination.
At any rate, drag Thriller Part 3 back onto the Animator Controller palette:
And NOW if you press play, you have an absolutely thrilling result:
I have skipped over a lot here, because I just wanted to get a success path documented that shows how to get the basics in place.
Now that you have a recipe for success, go do something interesting in YOUR game!