Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

AnimationUtility.SetEditorCurve makes clip file size bigger?

Discussion in 'Animation' started by oppaikir, Jun 10, 2016.

  1. oppaikir

    oppaikir

    Joined:
    Jun 17, 2015
    Posts:
    3
    Hi, I jusy try to duplicate AnimationClip data from FBX file, and remove some unuse curve.
    Oh it's Generic Animation, not Humaroid.

    First, I use Ctrl + D to copy, the *.anim file size just as same as my script at this moment.
    Then I use GetCurveBindings & SetEditorCurve to remove some bone's localPosition curve.
    But after I remove curves, the *.anim file size become over than double size!! (182KB => 446KB)

    I check the *.anim, and found some auto created data :
    「m_EditorCurves」「m_EulerEditorCurves」and「m_ClipBindingConstant: genericBindings」
    I remove these manually, and in Unity, nothing change. My Clip animations still work fine.

    Are these auto created data necessary?
    And how can I remove these by Unity Editor API?
     
  2. TeBeer

    TeBeer

    Joined:
    Jun 25, 2013
    Posts:
    1
    I stumbled upon this as well.
    Calling AnimationUtility.GetCurveBindings(clip) caused the asset size and memory usage increase quite alot. However, it only affected the asset size in editor. It was still a problem though since the profiler showed too high memory usage for animation clips in editor.

    The solution was to remove the additional variables using SerializedObject like this:
    Code (CSharp):
    1. var so = new SerializedObject(clip);
    2. so.FindProperty("m_EditorCurves").arraySize = 0;
    3. so.FindProperty("m_EulerEditorCurves").arraySize = 0;
    4. so.ApplyModifiedProperties();
     
    hankchen, damikuru and oppaikir like this.
  3. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    287
    Editor curves are necessary to render/edit the curves properly in the Animation Window.

    They are automatically stripped when building a standalone version.
    Also, the true memory cost of an animation clip is visible in the inspector, in the information box at the bottom.

    I would recommend against removing this from your clips, just as I would strongly recommend against profling in the editor; because your numbers will be wrong for almost everything.
     
    oppaikir likes this.
  4. AKQJ10

    AKQJ10

    Joined:
    Feb 9, 2012
    Posts:
    33
    Hi, David,
    I have read your posts about using SetCurve() on unity animation clips.
    We have a script that saves rotation curves on some bone transforms, but they are broken into segments instead of a continuous curve. The yellow curve has several segments that jump from -180 to +180.
    View attachment 336046
    The animation clip plays just fine inside unity, but we exported the animation to FBX (using the official FBX exporter by Unity). And later opened them in MAX, and MAYA, that particular bone is flickering like crazy.
    Is there anyway to fix this?
    I have already tried AnimationClip.EnsureQuaternionContinuity(); but that didn't fix the problem.
    Thanks a lot in advance.
     
  5. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    287
    Pasting my reply to your private message, so that others can benefit:

    What you are seeing is a very common problem when using Euler angles, across pretty much every software that uses them.

    The Euler angles you are using to create your curve have been generated from a quaternion, and Euler angles generated that way are always in the -180..180 range.

    So, when your Euler angle crosses that boundary, the Axis flips to -180 instead of 181.

    DCCs often offer filters to correct this, but Unity doesn't.

    To avoid this without having to code your own filtering, instead of using SetCurve to change Euler angles, you should be setting m_LocalRotation.x, m_LocalRotation.y, m_LocalRotation.z, m_LocalRotation.w from the local Rotation quaternion of the Transform.

    Otherwise, if you are in the Editor, you should be using https://docs.unity3d.com/ScriptReference/AnimationUtility.SetEditorCurve.html, which may help a bit, because it does some post processing on the curve.

    Finally, other applications might not interpret the curve the same way, so that might be why it plays fine in unity, and wrong in other applications.
     
    AKQJ10 likes this.
  6. AKQJ10

    AKQJ10

    Joined:
    Feb 9, 2012
    Posts:
    33
  7. StevenGerrard

    StevenGerrard

    Joined:
    Jun 1, 2015
    Posts:
    97
    Test these code ... this is not work in unity5.6.4 ... just simple get and re-save curves will remove the editor property ... for example code below:
    Code (CSharp):
    1. AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(clip, true);
    2. clip.ClearCurves();
    3. foreach (AnimationClipCurveData dt in curveDatas)
    4. {
    5.     clip.SetCurve(dt.path, dt.type, dt.propertyName, dt.curve);
    6. }