Script-generated animation clip produces strange results...

I’ve written a script that parses a series of .json files and converts the data into an AnimationClip. When I look at the animation curves in the Animation window, it looks like everything is correct, but when I drive the animation of a Transform with the clip, I’m seeing numbers in the inspector that don’t correspond to the animation numbers at all.

In the screen below, you can see how my scene is configured. The animation clip is on an AnimationTrack on a Timeline. The values for the current frame of the animation do not align at all with the values in the inspector. The transform is at the top of the scene hierarchy so there is no conceivable way that some kind of scaling transformation is effecting the position.

Here is the applicable code I use when setting up the animation curves on the AnimationClip before saving it to the asset database:

clip.SetCurve( "", typeof(Transform), "localPosition.x", posXCurve );
clip.SetCurve( "", typeof(Transform), "localPosition.y", posYCurve );
clip.SetCurve( "", typeof(Transform), "localPosition.z", posZCurve );

It all seems pretty straightforward to me, but this is the first time I’ve created AnimationClips in code so maybe I am missing some critical step/setting?

Can anyone help?

tried making an animation clip with just a linear progression in a for loop to see if I got the same strange behavior:

for ( int i=0; i<302; i++ )
{
    var time = (1/30f) * (float)(i);

    posXCurve.AddKey( time, i * .1f );
    posYCurve.AddKey( time, i * .1f );
    posZCurve.AddKey( time, i * .1f );
}

It looked as I expected! Strange!

After a lot of digging around, I found some settings on the Animation Playable Asset itself that I tried messing with and it turned out that unchecking the “Remove Start Offset” box lined the animation up to the right values.

I guess it was using the first position in the sequence as the origin offset for the rest of the animation. And since the first frame of my test animation from the for loop was at 0,0,0 it wasn’t necessary for that. Hmm… weird. I wonder if there is a way to fix the clip so that this isn’t a necessary step in the workflow…