Getting animation into Unity

Hello.

My problems never end! After many hours of playing with FBX I give up, it seems utterly useless at anything other than taking models into Unity with one UV map, which I can do with OBJ anyway. What I’m trying to work out is how to get animation in. I’ve tried Maya, Cheetah and Modo. Maya and Modo give me odd results, the models just fly around randomly, and Cheetah gives me no end of crashes. I can’t buy more software, there must be a way.

So, what are you all using to get character animation, or simple cubes moving around for that matter, into Unity? Please, I need to sleep and I need to achieve something today otherwise I’ll end up giving all my money to the pub tonight, and I’ll have a bad day tomorrow! :slight_smile:

Help.

E.

What kind of results are you getting? FBX from Maya to Unity is really simple for skeletal or non-deformable mesh animation. I’ll write up two simple examples for you to try. Since you have Maya we’ll use that. I’m using Maya 2008 and Unity 2.5 with the FBX 2009 exporter.

Example 1) The basics! Get a simple cube moving up and down in Maya and export it into Unity where it is also moving up and down.

  1. Set Maya to be at 30fps with Meters as working units and animate a cube moving up and down with key frames at 1, 15 and 30, 30 and 1 are the same. Plateau the tangents at 1 and 30 so you have a nice loop (even little tests should look good, no?). This will give us a 1 second up/down animation in Unity unless we speed up or slow down the animation at run-time.

  2. Select your cube mesh and export as FBX which should bring up the FBX exporter window. Set FBX version to FBX200900. Check ‘animation’, ‘bake animations’, ‘curve filters’ and turn OFF 'deformed models;. Also turn on File Units converted to: Centimeters which sets the scale factor to 100.0. You should get a confirmation message about the log file and what occurred during export.

  3. Open up Unity and if you exported your Cube to a unity project it should be visible in the Project window. It should also have two components, one for the cube mesh and once called Take 001 which is an animation clip. Since you changed the export settings to convert Units to centimeters you do not have to change the Scale Factor settings in Unity. This isn’t such a big deal for the simple cube but for skeletal it’s important that we DO NOT change this.

  4. Drop the cube into your scene, make sure your camera is looking at it and press play. Your cube should move up and down once and stop. You can change the ‘wrap mode’ (what it does when it ends) by selecting the cube object in the hierarchy and changing the Wrap Mode settings in the inspector.

Example 2) Animate a simple cylinder with skeletal deformation and get it playing in Unity. A couple notes… I’t a bad idea to put key frames on meshes or joints. Will it work if you do? Yes, but more often than not you’ll end up having to make changes to your skeleton, your mesh or both and the time is in the animation not the rigging. I always build a nurbs control rig for everything I animate, even the simple cube.

  1. Build a simple cylinder with enough subdivisions to support deformation (obviously meshes only bend if vertices allow for it). Draw a joint chain in your cylinder that looks like it’ll work. I’m using 4 joints which are obviously connected by 3 bones.

  2. Perform a ‘Smooth Bind’ in Maya. I’m setting max influences at 4 as Unity supports 1, 2 or 4. If you’ve forgotten, this is how many bones can influence a vertex. When you build your projects in Unity this is a very important setting and we’ll drop influences as needed for various build types Web/EXE, etc.

  3. Set your mesh so it can’t be selected – your mesh should be standing alone, not part of a hierarchy and should not be moved or have any keyframes on it. Animate your joint chain moving up and down and rotate some of the joints (as before, this is only a test but make it look nice :)).

  4. Select the root of the joint chain (it should be a single hierarchy) and your mesh and export selected as FBX. Use the same setting as the previous example but make sure the start and end range matches the length of the animation you want to export. Check ‘Deformed Models’ and make sure ‘Skins’ is checked in the deformed models sub menu. Don’t forget to set your scale factor to centimeters! Export that sucker.

  5. Cylinder should show up in Unity with the joint hierarchy, the mesh and the animation clip. Drop it down in your scene and it should move just like it did in Maya.

Example 3) Controlling your animations is remarkably simple but skeletal animation, weighting and blending in Unity aren’t as powerful as in some of the huge AAA engines (Source, Unreal3). This can actually be a good thing as it keeps the simple tasks simple and still provides acceptable (or better than acceptable) results.

  1. Select your cylinder in the project window. Add some named animations by pressing the little “plus” symbol in the Inspector Animations Name box. Name the animation and set the start and end and turn on loop if needed. Remember, if you exported an entire loop from Maya where the first and last frames are the same this is a good place to drop the last frame.

  2. Write a simple script to control the animation clip you just set up and named. Something like:

function Update () 
{
	if (Input.GetKeyDown ("space"))
	{
		animation.CrossFade("my_animation", 0.5);
		animation.wrapMode = WrapMode.Once;
	}
}

Apply the script to the cylinder in your scene. Whenever you press the space bar the animation plays once. I’m using “CrossFade” instead of “Play” because it allows me to add in animation and blend between them. If you don’t want your cylinder to animate automatically when you run your scene turn off ‘Play Automatically’ in the inspector for the cylinder as selected in the hierarchy.

I hope this helps!

I use Maya and have no issue what so ever. Following the docs it worked the first time. It works it’s not an issue with unity or the software, it’s an issue of you doing something wrong.

Follow jbuck’s examples it should help. Also I believe there are also video tutorials out there on this subject.

So you spent $3000+ on software just trying to get animation to work?

Calm down wadoman, I know it’s me.

No, I didn’t spend that amount to just try animation, I’ve been using Maya since pre version 1. Unity I’ve been using for about 3 weeks, fbx, about 2 days. I am a modeller by profession and use Modo in my day job, but have always used Maya for animation. For me it was not the Maya side of things that were not working, but the Unity side of things.

Anyway, it seems something is still going wrong. I can get animated meshes into Maya, but 1 time out of every 3 it will fail for no reason that I can see. The mesh goes in with the animation, but the mesh will be stretched hugely along Y and the animation appears to be very corrupt. A re-export sometimes fixes it, with nothing changed, other times I have to alter something unimportant and re-export to make it work, but again sometimes this will not fix it.

Modo has given me the worst results, but this seems to be a Modo FBX issue that many are aware of. Maya gives me either perfect results, or a mess. I honestly have never had success with FBX so it doesn’t surprise me.

jbuck, thank you for the detailed response. :slight_smile: I’m going to check out some system settings and try killing prefs etc and will let you know the end result.

What you’re describing (the stretching) is a result of your import scale not matching your export scale. Read the part I posted about export settings and unit conversion.

??? huh OK

I guess you took my post the wrong way. My bad then.
No offense intended.
Good luck

Sorry, I’m stressed to the max right now and taking everything bad. Apologies.

I’ve lost count, but think it’s 4-5 days of trying to get animations into Unity, even now with all the advice and research it’s still a 50/50 at best if it’s going to work. I’m not a Maya newbie, as I said I’ve been using it since before version 1 professionally. It’s going to be something stupid, simple, and impossible to find. :slight_smile:

No worries.

Its always something stupid and simple. I go through that kinda crap all the time myself.

When I started testing animation for unity with maya. I did it in steps. I started with a simple box with a rotation animation. Then if all worked well I tried importing a simple skinned cylinder with 2 bones and no animations. If worked I then imported it with animation and then multiple animations. At that point I was confident with doing a whole character.

It was easier for me to manage any problems that may arise in small segments, instead of trying to debug fully rigged skinned animated character.

I’ve gone through it time and again, like I say some exports will work fine. Then, using the exact same settings, it will stretch, save again, it wont. I am now thinking it’s not anything to do with Maya, Unity or FBX, but thinking it’s a system or software preference. Next thing will be to re-install all the effected apps.

I wont get my pipeline working tonight, but I’m determined to get it working tomorrow. Wine depending that is! :wink:

Not sure if this will help at all, I think maybe not, but here is another thread about Maya animations. If anything maybe it will be helpful to others that visit this thread needing Maya animation help. I just think it’s helpful to the community if threads contain links to other relative threads to help speed up the process of finding solutions.

http://forum.unity3d.com/viewtopic.php?t=20193

Anyway I hope you got some sleep and had luck with your animations.

Thanks guys, I’ve only been using Unity for a couple of days and this page made object transform animation export from 3dsmax a snap :slight_smile:

Hi all.

I just wanted to say after a break, some sleep, a few Gin and Tonics and some graft it’s now working perfectly. :slight_smile: We now have stuff blowing up leaving smoke trails etc in Unity. This is fun. :slight_smile:

I wanted to say thanks for all the help. :slight_smile:

E.