AnimationUtility.SetEditorCurve makes clip file size bigger?

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?

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:

var so = new SerializedObject(clip);
so.FindProperty("m_EditorCurves").arraySize = 0;
so.FindProperty("m_EulerEditorCurves").arraySize = 0;
so.ApplyModifiedProperties();
3 Likes

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.

2 Likes

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.

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.

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 Unity - Scripting API: AnimationUtility.SetEditorCurve, 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.

1 Like

Thanks a lot, David,
I will try the SetEditorCurve() method.

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:

AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(clip, true);
clip.ClearCurves();
foreach (AnimationClipCurveData dt in curveDatas)
{
    clip.SetCurve(dt.path, dt.type, dt.propertyName, dt.curve);
}