Search Unity

Guide: Exporting Complex Rigs from Maya to Unity

Discussion in 'Asset Importing & Exporting' started by BotMo, Mar 25, 2011.

  1. BotMo

    BotMo

    Joined:
    Mar 2, 2011
    Posts:
    101
    I just found myself in fairly difficult situation recently with a very complex rig which went berserk every time i tried to export it. When I hopped onto the forums I found that several people had similar issues, but there wasn't a clear solution. So this is a brief how-to for those that find themselves in a similar situation. Beware, this method does take some time, but it will probably be faster than starting from scratch.

    A brief intro: I'm working with a fairly complex rig. FK/IK switching, set driven keys, multiple skeletons, constraints, parenting, multiple skins, etc. I animated a model without any forethought of "will this export?" well.. no it didn't. Not without a lot of work.

    The main problem is the FBX exporter (my version is 2008) will not export animation curves or constraints correctly, so to say the least, this causes some problems.

    *note: I'm on maya 8.5, but most of this info should still be relevant.

    **I highly suggest making a pre-export version of your animation and a post-export version. Once you go through this process, it can be difficult to make any changes to your existing animation. Likewise, it is best to finish up all of the animations on your model before going through these steps.

    ***for future reference, if making a rig from scratch it will be best to just use parenting when you can instead of using constraints (or parent constraints) This can limit your rig significantly though, but you won't have to go through all of the hassles I outline here.

    --Step 1:

    Your animation is awesome: Yay! Try to export it as an FBX. Open it the FBX in maya. Surprise! It's all messed up! One of the big problem here is probably constraints. Some constraints won't work, sometimes the skin decides to attach to your FK instead of the IK. If it does work, then you can skip this guide and be happy.

    --Step 2:

    Make sure you have a bind-pose. If you didn't create a bind pose, this is the time to do it. If you didn't, then go to frame 0, zero out all of your controllers. If your using a rig with splines, this may be problematic as splines often move your rig a little. Try to get it as close as you can to your bind pose. If you need to, you can load your bind pose model and just try to match everything up as close as you can. In both cases, if you are close to the bind pose, then set keys for every controller at frame 0.

    --Step 3:

    Clean up your scene. Remove any reference objects, old models, and go through the hierarchy and see if there are any animation controls or joints that are just hanging around. Try deleting things if you don't know what they are (normally it's not smart to just delete things randomly, but extra junk will just add complications now) <<be sure to save your file before doing this!!!>>

    If you don't know what it is, delete it. Play the animation. Look at the texture. If everything is still working, then go ahead. If not, then control-z or reload the scene.

    In my case I had some old parts of the model which had somehow become invisible. The only way to find them was to look in the hierarchy view and delete them or to export the whole scene as FBX and load it into a new scene.

    --Step 4:

    Go to your working .mb file. Select every joint that you see. Not just "drag" select, but go into the hierarchy view and select every joint in the model. Don't select constraints/controllers/geometry. You may need to bake controllers or constraints later, but don't do it yet.

    --Step 5:

    Make sure your entire animation range is viewable on the time slider. We need to bake all of these keys. Baking may be inefficient, but the alternative is to either delete your rig and animation and start again, or to limit yourself to simple rigs. Personally I'd prefer to go through the hassle in order to use a clean and smoothly animating rig.

    [Edit > Keys (option box)]
    Hierarchy: Selected
    Channels: All Keyable
    Time Range: Time Slider
    Sample By: 1.000 <---you can change this if you like, but there may be some problems especially if you're using constrained objects which aren't part of the main mesh.

    Leave the rest at default.

    {Bake} -Maya will set keys for every frame of animation (or whatever you set it to via "sample by")

    --Step 6:

    Export as FBX again. This is where the headaches start. (choose export all)

    Geometry:
    -smoothing groups (yes)
    -split per-vertex (no)
    -convert to null (no)
    -convert to nurbs (you shouldn't be using nurbs so leave it as default)

    Animation: (yes)
    -bake animations (yes)
    -start and end at the span of your time slider
    Deformations: (yes)
    -Skins (yes)
    -Blend Shapes (no, because unity can't use them)
    Curve Filters (yes)
    Geometry cache files (yes)
    Contraints (yes)
    Character Definition (yes)
    Cameras(no)
    Lights(no)
    Embed Media(no)<--note. It seem this doesn't work anyway in 2008. For me, it always exports my materials as pure black whether or not I choose to embed media.

    leave everything else as default.
    *note - im not sure exactly if all of those boxes needed to be checked, but this is what worked for me after a lot of guessing. There may be errors. Just ignore them for now.

    --Step 7:

    Save you current scene as my_scene_name_fbxprep.ma or whatever you want to call it.

    Open a new scene. Import the FBX file. Play the animation.

    There's a good chance that if your using a complex rig with alot of constraits that your rig will be broken and the animation will still be messed up. It may even look worse than it did before. If you rig was simple enough everything may look ok now. If so, congrats! However.. if you're like me. It's worse in some ways, better in others.

    if you had bones that were just moving wherever they felt like it, they should at least be in their normal spot. If not, then select every joint and make sure there's a key on every frame. The important thing here is that your joints are animating correctly.

    Look at your controllers. If they are detached from the rig, then their constraints didn't export, but because the joints are baked the joints animated correctly. However, if you have controllers that are still attached, then they did export correctly. If the animation on those is messed up, go back to your .ma, bake their animations the same way you did the joints, and reload your FBX.

    --Step 8:

    Next problem: Multiple skeletons. For my rig, I had multiple skeletons that were held together using constraints. The constraints didn't export. Go back to the broken FBX. Parent any broken segments of the skeleton to the rest of the rig. You need to have one cohesive skeleton in order for everything to work correctly. In my case, the legs needed to be parented to the spine, the arms needed to be parented to the top of the spine, and the neck to the top of the spine. This may confuse maya even further and mess up your mesh considerably. See the next step.

    You should be doing all of this from frame 0 on the FBX file. You can save this as a new file if you choose.

    If at this point your joints are all animating correctly, then you're halfway there. If not, then there may be other issues.

    --Step 9:

    At this point, my joints all looked good but my skin was still really messed up. It decided to bind to my FK and IK joints. No matter what settings I chose, this always occurred. Why did I make a point to go to the bind pose? You guessed it! Animation > Skin > Detach Skin

    If you have FK/IK joints, now is a good time to delete them to avoid having to deal with more joints than you need. Since your animations are already baked, you don't need both FK/IK. For my rig, I deleted the IK arms/hands and the FK legs. If both of them are animating correctly just delete whichever you think will work better.

    --Step 10:

    Re-Skin.

    --Step 11:

    Re-export. Save your scene. Open a new scene, import your FBX. It should be back to it's normal self again. If you end up with material problems, you will need to manually load those into Unity. No matter what I did, my materials exported as pure black even within maya and the FBX exporter created something like 200 grey Phong materials.

    If there are still problems, check your constraints. I had issues with the weapons my character was holding. They were parented to the wrist controller, which was parented to a group that was parented to the elbow.. etc.. etc.. all of the constraints (and maybe groups) needed to have their keys baked as well because FBX couldn't export the curves correctly.

    --Step 12: Bring it into unity. If the FBX file worked in maya, it should be close to the one in Unity. For mine, there were still some issues with curves failing to import so I had to bake again.

    If all else fails, add a comment and maybe I can help.
     
    Arodin_C likes this.
  2. pete_shand

    pete_shand

    Joined:
    Jun 23, 2011
    Posts:
    1
    This is a really great post, thanks for this.

    In case anyone is interested, I've found that supercrumbly's Auto Rig creates rigs that are compatible with unity. At least in my experience.

    http://www.supercrumbly.com/3d.php?sid=173
     
  3. kenny709394

    kenny709394

    Joined:
    Aug 1, 2011
    Posts:
    2
    Hi Bot Mo,

    Thank you for the sharing this is really great. So I am sharing my situation here.
    I am trying out my animation with maya 2012, Unity just doesn't recognize my constraints that I setup as controllers for my ankle bones.
    But the rest of the animation is correct.

    Other then that, I don't have encounters any other problem with the autodesk maya 2012 fbx exporter.
    But I think I'll use your parenting method instead of the constraitns. :)

    But I have seen some unity tutorial on youtube there don't have any problem exporting those constraints. :/ Really weird.
    Good luck.

    Cheers,

    Kenny
     
  4. Whtrbt4

    Whtrbt4

    Joined:
    Aug 2, 2011
    Posts:
    2
    Hi BotMo!!!

    Ive an issue with my animation, and i really hope someone has had it and hadit fixed already.

    I have a character witha simple rigg but once i export it as FBX and import it to Unity, the mesh looks like collapsed o smashed, sometimes the animation stills intact, sometimes isn't even there, but thew main issue is the mesh; it's all smashed and i've tried a lot of things and it seems useless, the mesh is still SAMASHED jejeje. Is quite frustrating, really!!!

    So, someone has any idea how to fix this and can help me please!!! please!!!!

    Thanx and see u round!!!

    ps: By the way, im using Maya 2011 (FBX 2011.3) and Unity 3.3
     
  5. dangermouse

    dangermouse

    Joined:
    Nov 28, 2009
    Posts:
    73
    I just thought I'd throw my solution in here. It's much simpler in concept, but takes a bit more work. very flexible though. (Maya)

    Build your rig, controllers, constraints, what have you.

    Make a copy of all the joints. JUST the joints, and their hierarchy. If you've got split hierarchies or anything, this will still work, just be careful. This is also a good opportunity to combine multiple skeletons into one if you need that. The hierarchies don't necessarily have to match.

    Now, you can easily do this with a script, but for now we'll do it manually. Walk through your nice clean joint copies, and parent/orient/scale constraint them to the rigged ones.

    Skin your mesh to your new skeleton.

    When it comes time to export, back your file up.

    Bake the animation.

    Delete your rigged skeleton.

    Export.

    It may seem like a bit of hassle, but this has fixed previously unfixable rigs, and saved us a lot of headaches. It's just one more technique to consider.