Search Unity

Importing FBX animation: Weird results

Discussion in 'Editor & General Support' started by McFadge, Jun 19, 2011.

  1. McFadge

    McFadge

    Joined:
    Jun 19, 2011
    Posts:
    18
    Hi guys, first post on the forums :)

    I'm currently importing animations from Maya 2011 into Unity 3.3.0f4 (63135) via FBX (2011.3) and am running into a few problems. (Windows 7 64bit too, if that could be relevant).

    I can't seem to get consistent curves between the two programs. I've been testing for hours now and decided to see if anybody else had some answers.

    It seems that no matter what my curves I use in Maya, Unity decides to tweak the tangents on certain keys.

    So in my most obvious example, I baked animation for every key. I then set the tangents to be flat. In Maya, this results in the curves looking as follows:



    And in Unity, this is how it looks for the root (hip) joint:



    Seems fine, right? But EVERY other animation curve looks like this:



    Nice and smooth, which isn't what we expected.

    It seems Unity is overriding the tangents from the imported .FBX file?

    This can also be seen below in a different case, where the tangents produced by Unity have created an overshoot:



    This is fixed by using the animation compression, but it just seems weird to be happening when I didn't specify it.

    I realise I could create duplicates of the animation sets and then fix them in Unity, but obviously that is VERY undesirable (animating twice isn't the best solution).

    Another problem I'm having in a more 'real-world' situation is that Unity isn't interpreting my key data properly.

    Below is a screen shot in Maya, and a second in Unity:




    See how the keys aren't on the right frames? I've tried FBX 2009, 2010, and 2011 - no dice.

    Anybody got any answers? I'm going crazy over here :-|

    Apologies for the long post, I just wanted to be thorough in my explanation.
     
  2. McFadge

    McFadge

    Joined:
    Jun 19, 2011
    Posts:
    18
    Sorry to bump, we're just really running out of ideas on what could be causing this.
     
  3. McFadge

    McFadge

    Joined:
    Jun 19, 2011
    Posts:
    18
    Okay, after quite a bit of research I believe I've found the answer. It's because Unity uses Quaternion Cubic rotation interpretation. From Autodesk's Maya user guide (http://download.autodesk.com/global...d_rotation_in_Maya.htm,topicNumber=d28e197502) are some advantages and disadvantages:

    Bolded is the important section. After mucking around in Unity for a bit, I've found that you can set the rotation interpretation of animated curves in Unity. However, this isn't possible for read only animation files, which is what you are given when they are imported. Is there really no way to default to Euler curves for imported files?

    This seems like a crippling decision, what, with the lack of tangent handles. Surely there's an option, otherwise how are other animators getting around this issue?

    If I don't get a reply soon, I suppose I'll make another thread with a more precise goal, seeing as I now know what I need to achieve.
     
    Last edited: Jun 21, 2011
  4. svenskefan

    svenskefan

    Joined:
    Nov 26, 2008
    Posts:
    282
    How about creating copies of your "embedded" read only animations and operating on them instead?
     
  5. DFT-Games

    DFT-Games

    Joined:
    Jun 24, 2010
    Posts:
    454
    Hi,

    are you sure to have the Unity FBX importer set to Import tangents? Its default is Calculate ;)
     
  6. McFadge

    McFadge

    Joined:
    Jun 19, 2011
    Posts:
    18
    Two reasons:

    1. I will have to go through each bone and set the rotation interpolation to be Euler. We haven't nailed down the pipeline yet, but I'm leaning towards multiple animation files for a more flexible workflow (multiple animators). As you can imagine, setting the interpretation mode for each bone over several animation files would be a nightmare.

    2. I don't really want to separate the animations into duplicated files. The idea behind importing the maya file directly is to make the workflow easier by editing what's needed, closing, and Unity updating automatically.

    So yes, it would work, but it really isn't very practical, sadly.

    Yeah, I tested this option before I came to my conclusion thinking it might help. Unfortunately it doesn't though (just checked again), and because it's not under the animation section of the FBX import settings, I believe it is referring to the tangents of NURBs or shape objects (I'd have to test that though). The fact that my flat tangents came across on the root bone, which has translation data, seems to support this theory.

    Thanks for the suggestions though guys.
     
  7. svenskefan

    svenskefan

    Joined:
    Nov 26, 2008
    Posts:
    282
    I have no experience with this problem whatsover, just trying to be helpful ;)

    1. Wouldn´t it be possible to create an assetimporterscript that would do this automatically for you. I think it is.
    2. agree totally, sometimes you have to let pragmatism rule over cleanliness though
     
  8. McFadge

    McFadge

    Joined:
    Jun 19, 2011
    Posts:
    18
    I'll look into the assetimporterscript, thanks for that idea.

    I just find it odd that nobody else has run into this issue?
     
    Last edited: Jun 21, 2011
  9. an

    an

    Joined:
    Oct 6, 2009
    Posts:
    146
    Sorry that i can't really help you, but why aren't you importing the maya binary file if you work with Maya? In the background, Unity lets Maya create a FBX, too, but I think it also sets some parameters so everything works better together.
     
  10. Edwige

    Edwige

    Joined:
    Nov 25, 2010
    Posts:
    35
    Something to keep in mind to have properly imported animation is to bake these animation => one key at each image ! it avoids interpolation issues :) (in Maya, it is called Bake Simulation)
     
  11. McFadge

    McFadge

    Joined:
    Jun 19, 2011
    Posts:
    18
    Hi lunio, thanks for the response. You're right, after finding out you can just use maya files (ascii in our case), we have switched to that method of importing animation. The issue still occurs, however, as the keys are still having their tangents eliminated. However, it will fix my earlier issue with the 'moving' keyframes, but only by adding extra ones everywhere :p This isn't so much my concern now, as the curves are still the same.

    All the keys have been baked, however, the tangents on these keys are being eliminated when the Euler rotations are converted to Quaternion rotations. Thinking about it now, chances are it won't be too bad/noticeable as this will only affect the rotational values, and will only affect them badly when the change in rotation is quite sudden.

    So I may just have to live with this if their isn't a way of defaulting the curves to Euler (which would be desirable). The game won't run at 24 FPS (which is what I animate at), and so information between the keys will be used to rotate the objects in the scene. This is where the problem comes in, because I can't control the tangents on these curves, and so it can result in overshooting and unwanted easing, etc. (see my fourth image).

    But yeah, now knowing this is limited to rotational animation, and that it only occurs when the differences in keys is quite large, this should be mostly avoidable. It's just annoying to work around this restraint when Unity clearly has the capability to use Euler values :(

    And actually, after a bit more testing, converting the rotational interpretation from Quaternion to Euler will still require cleaning up keys and such afterwards in Unity (especially considering the whole 0 = 360 thing). So yeah, I think I'll just keep in mind where the issue occurs, and do my best work around them.

    I hope that adding an option to use Euler curves upon import (the tangent data etc. is all there) is considered for the next release of Unity, as it's a feature I greatly anticipate :)

    So yes, I think I'll leave this thread as it stands.

    Thanks everybody for your help!

    EDIT: Thanks to Edwige, I've actually found out that the curves between two keys on ones don't mean diddly-squat! Now I'm mystified as to where it gathers that data :p Anyway! Thanks again everyone, I've learnt a lot!
     
    Last edited: Jun 21, 2011
  12. Nick4T2

    Nick4T2

    Joined:
    Dec 9, 2011
    Posts:
    11
    Hi McFadge - just wanted to add I've been having similar problems regarding Quaternion vs Euler angles and I was really grateful to find this thread as it's shed a lot of light on the specific problems I've been having. I'm also mystified that more animators haven't been running into this problem.

    In my case, we are using animations from Mixamo, which then ideally we would edit. In practice however, duplicating and editing the .anim files has led in most cases to the end keyframe returning NaN on rotation values, which makes Unity crash if the anim is called at runtime. The workaround I've found is to convert the curves to Euler in the Unity animation editor, which means they can be edited without keyframes returning NaN. However this means the curves operate totally differently and require a lot of cleanup and editing to even remotely resemble the original anims.

    Being able to import curves as Euler would in theory get around this problem - I'm not 100% sure, but it would be good to have the opportunity to test out my theory :(

    Anyway many thanks for the thread, glad to know I'm not alone as I didnt get a single response to either my question in Unity answers or my forum thread. If you get this I'd love to know if you made any further progress on the issue?

    Cheers,
    Nick
     
  13. McFadge

    McFadge

    Joined:
    Jun 19, 2011
    Posts:
    18
    Hey Nick,

    I've actually learnt a lot since I experienced this 'issue', and found out that a lot of the things I was worried about don't actually have any effect on anything. For example, the data provided by the curve between single frames doesn't affect animation in Unity, as I mentioned earlier learning from Edwige. However, I'm still yet to work out how it will create that data if you slowed the animation down, or something of that sort (I imagine it would interpolate linearly).

    However, your issue sounds very different and does deserve attention. I'm still very new to animation, game development, and Unity itself, so unfortunately I don't have any answers. I would suggest filing a bug report and seeing if the Unity team can help you. It's very strange for it to throwing NaN though... Have you tried converting the curves to Euler then back to Quaternion in a duplicated animation file? Does it still provide the NaN error?

    Also, for others, regarding something I learned from my time with Unity, change the Animation Compression value for Rotation. While the Scale and Translation values can be okay depending on your scene units in Maya, Compressing the rotational values to steps of .5 has VERY noticeable results. We ended up turning animation compression off, but I can't comment on how this affected performance (we were still hitting our target frame rate and the animations were finally looking correct, so we were fine with it). Originally I thought this was caused by the weird animation curves Unity was creating.

    Anyway, hope some of this helps you or somebody else :)
     
  14. Nick4T2

    Nick4T2

    Joined:
    Dec 9, 2011
    Posts:
    11
    Hi McFadge, just back after my Xmas break :)

    Thanks very much for the response and very glad to hear you managed to get your animations sorted in the end. I'm still stuck in the mud unfortunately - I did try converting to Euler and then back to Quaternion but it does still provide the dreaded NaN error (Quaternion To Matrix conversion failed because input Quaternion is invalid {-1.#QNAN0, -1.#QNAN0, -1.#QNAN0, -1.#QNAN0} l=-1.#QNAN0), so I'm still looking for solutions. Have opened a bug ticket with Unity but no response so far. I'll post again when/if I manage to make a breakthrough. Thanks again for the dialogue :)
     
  15. a.callum

    a.callum

    Joined:
    Apr 24, 2011
    Posts:
    5
    Hi, I believe I ran into the same results last year, you can view my thread here http://forum.unity3d.com/threads/86...imations-imported-from-Maya-2011-(screenshot)

    I was no way as understanding of the technical level back then so it was a very visual way of finding a solution, but it was the Unity version in general that was buggy. After I upgraded to 3.4 the FBX importer handled the animation import perfectly
     
  16. Nick4T2

    Nick4T2

    Joined:
    Dec 9, 2011
    Posts:
    11
    Hi a.callum,

    Thanks for the reply - I had a look at your thread and I think your problem is slightly different in that I'm having no trouble importing animations, the trouble arises when trying to edit imported animations within the Unity IDE - doing this always produces a NaN error on the end keyframe.

    I have received a response from Unity Support which states they are aware of the problem and advisng me to upgrade to the Public Beta of 3.5, which I can't really do as we are mid-project and any upgrade would need to be done across the team, which our Senior Coder doesnt want to risk until this project is out of the door. I've asked if there is any way to resolve it in 3.4.2, but either way it looks like it's a waiting game.

    Anyway thanks for the input and I'm glad you got your tank working eventually! :)
     
  17. Nick4T2

    Nick4T2

    Joined:
    Dec 9, 2011
    Posts:
    11
    In case anyone is following this - Issue is now fixed in Unity 3.5 Beta. Thanks again everyone for input and support :)
     
  18. adur

    adur

    Joined:
    Sep 8, 2011
    Posts:
    37
    I was having the same issue where I was exporting out of Maya and finding weird jitters introduced by the fact that the tangents where being modified by Unity. It was driving me crazy and changing the settings to the tangent import and so on wasn't making any difference. Same with trying Euler or Quaternion on export.

    Finally, I tried using fbx 2011 instead of 2012 on the Maya fbx export settings and it seemed to solve the issue for the most part. It still had a couple of broken tangents here and there but it was so minimal that you couldn't tell once you played back the anim in Unity, you could only tell if you took a look and zoomed in on the curves in Unity.

    Hope that helps somewhat...
     
  19. morganimation

    morganimation

    Joined:
    Oct 18, 2013
    Posts:
    3
    Replying to this thread because it's 2014 and there still doesn't seem to be a practical fix for this that I can find.

    (exporting from Maya)
    I've tried dae and fbx, multiple versions of the latter
    I've baked animations on single keys
    I've tried changing the wrapmode to loop

    The only solution I've found is going into the Unity Animation editor after import and fixing the keys by hand, which is time-consuming, impractical and means that I need to repeat the process every time I import an animation.

    I guess, as this issue has been ongoing for years now, that there isn't actually a fix for it, but here's hoping.
     
  20. morganimation

    morganimation

    Joined:
    Oct 18, 2013
    Posts:
    3
    solution

    It seems the only way around this, annoying as it is, is to separate all the animations into individual files, bake and export them to Unity.

    Apparently the weird interpolation comes in when the export file has a lot of keys in it. Reducing the number of keys (somehow) tricks Unity into accepting the animation curves you give it.

    Hope this helps anyone who stumbles into this bug.