Unity 4.x – Mecanim working on your own projects

Hey, as usual its been a while. This time Im switching technologies and solving an issue I had today. Ive started to play around with Unity and since I have some background on game programming I decide to go to the bone and start with the hard stuff.

My ideal starting point was simple: a square room scenario where I could move an avatar and add some monsters (possibly zombies) to shoot. I did some reading (up to chapter 5 of the book Unity 3.x Game Development Essentials) while I was traveling the pasts weeks which was the perfect introduction to the technology.

The first steps were a no brainier: the room is a .fbx mesh which I UV mapped and painted with some Doom 2 textures. I added a few details to make it interesting but nothing special (here is a screenshot). Moving something is also pretty easy, I just added the platform controllers to test.

The hard part to me was the animation part, with no background in this area I decided I would start with a tutorial: I end up choosing the Mecanim Animation Tutorial. I was REALLY interested on having my own rigged models “lending” animations, this is sometihng I really struggled while programming in XNA. I followed the first 20 – 25 minutes of the tutorial and I didnt want to see more, I wanted my model to move ! I started a new empty project, copied the Robot model and the Idle animation and I did exactly as told on the video: the result: NOTHING ! My model was showing a “falling” animation !!!

The reason is I was not setting up the environment properly (If you are wondering how I figure this out, I just started to “debug” visually the tutorial solution). Now I’m going to share the steps to have the Mecanim engine working in your own scene or project:

Start a new project (I added the Character Controller package, but I believe this is not necessary for this example)

  1. Import, from the Mecanim Animation Tutorial code (link) the Assets/Animations/DudeAvatar/Dude.fbx and select it on the Assets window
  2. On the Inspector, under “Rig”, change the animation type to “Humanoid”, Avatar Definition should be “Create from this model” and hit “Apply”
  3. Import (also from the tutorial code) the Assets/Animations/Idles.fbx and select it on the Assets window
  4. On the Insepctor, under “Rig”, change animation type to “Humanoid” and Avatar Definition to Copy from Other Avatar. On the Source, choose “DudeAvatar”. Hit Apply.
  5. Import the Assets/Tutorial/Robot.fbx and select it on the Assets window
  6. On the Inspector, under “Rig”, change animation type to “Humanoid”, Avatar Definition to “Create from this model” and hit “Apply”
  7. Drop your Robot to the scene and place it somewhere the camera can see it
  8. Create a new “Animator Controller”. Name it as you like.
  9. Open the Animator window and drop the “Idle” animation from your Idles asset (you will have to open it on the Assets window)
  10. Select your Robot on the scene, and under the Animator Component, change the controller to the one you just created.
  11. Run your game and now you should see your robot using the animation !

My problem was not importing the correct avatar (DudeAvatar) and I was not setting it up on the animation fbx.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s