Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

How to rig a character without getting thousands of keyframes on import?

Discussion in 'Animation' started by eobet, Nov 11, 2018.

  1. eobet

    eobet

    Joined:
    May 2, 2014
    Posts:
    176
    I just had a look at how the dope sheet looks in Blender and how it looks in Unity, and wow, it's a world of difference.

    What's just a few dozen keyframes in Blender get imported to what looks like an absolute mess of hundreds or thousands of keyframes in Unity.

    I suspect this is because I have rigged in Blender using inverse kinematic bone constraints.

    Without them, if I move the pelvis bone, the legs just follow, so I need an IK constraint on the feet to prevent them from going through the ground.

    Is there a way to do this and still get a clean import into Unity?
     
  2. DuckType

    DuckType

    Joined:
    Mar 21, 2015
    Posts:
    18
    My guess is that you're right - it's indirectly caused by your IK. Typically an IK will be baked down on animation export, which will generate a key per frame. This is the standard way of dealing with IK (any anything complex really) when exporting animation.

    There may be some optimization option Blender gives you on export to reduce the number of keys by getting rid of redundant ones. But you'll still have a lot more keyframes in Unity than in Blender.

    The only real way around this would be to export your IK target instead and use some live IK in Unity. There are some on the asset store. This does come at a price in terms of runtime performance but it shouldn't be too bad. It would involve some setup work though.

    I'd recommend just living with it, unless there's a pressing reason you don't want those keyframes in Unity. It's normal to have them there.
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,020
    If it's feet, and the character is human-like, there's built-in foot IK if you import the animations as Humanoid.
     
  4. eobet

    eobet

    Joined:
    May 2, 2014
    Posts:
    176
    Oh! Interesting... thank you for that information. What happens if I animated at 60fps and someone has a 144hz monitor? Will the animation get jerky?

    Turns out I already do that, and when I looked closer, it's actually the shoulder and neck bones which get a keyframe per frame. I have no idea why.
     
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,020
    No, everything's interpolated between the keyframes, just like in Blender.

    Figuring out what settings in blender are causing what to appear in Unity is a bit of a struggle. If you remove the IK constraints, do you get a sensible amount of keyframes in Unity? It's worth checking, so you know you're debugging the correct thing.
    How are you exporting? Are you exporting to fbx, or just dumping the .blend file in Unity?


    Also note that animating at 60fps will cause your animation files to be huuuge, which again increases load times for your game. Unless you actually need that many keyframes per second (due to animating something where the interpolation in Unity doesn't give good results), you should probably reduce it.
     
  6. Goatogrammetry

    Goatogrammetry

    Joined:
    Apr 27, 2017
    Posts:
    195
    Doesn't the importer have a "reduce/optimize keyframes" setting? I wouldn't worry about it. If you animated at 12fps (which is actually what classical animators used) you'd get less keyframes. Funny thing is unity just stretches them out to be 30 when it imports if you believe the numbers in the animation preview window. Looks fine though. You should ignore fbx filesize and whatnot since in a compiled game, Unity is going to grab what it needs and discard the rest. At least one hopes so.
     
  7. eobet

    eobet

    Joined:
    May 2, 2014
    Posts:
    176
    Thanks for the replies!

    I noticed a slightly floating effect on my feet before that I did not see in Blender. I wonder if that's Unity's foot IK which does that? I couldn't see a setting for it.
     
  8. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,020
    Foot IK is turned on and of in the settings on the state in the animator controller.