Animation clip snaps back to origin on loop after scripting animation import settings

I am using an editor script that sets up already importer animation files to quickly setup their import animation settings as multi-editing clips is not supported, at least as of 4.5.3. It grabs the modelImporter.clipAnimations and then creates a new array of ModelImporterClipAnimations with mostly copied information from the imported animation clips but I do change a few of the settings: keepOriginalOrientation, keepOriginalPositionY, lockRootRotation, and lockRootHeightY. I then set the modelImporter.clipAnimations to the new array. Everything looks fine in the editor Animation tab preview window with the character animated with root motion and moving across the grid, but when I select the actual generated animation clips and play them, the character snaps back to the origin and starts over when the clip loops.

Manually setting up the same animation clip and it works just fine.

Here is the main part of the code I am using:

static void ApplyAnimationSettings(string objectPath)
    {
        UnityEditor.ModelImporter importer = (ModelImporter) AssetImporter.GetAtPath(objectPath);

        PropertyInfo prop = typeof(ModelImporter).GetProperty("importedTakeInfos", BindingFlags.NonPublic | BindingFlags.Instance);
        TakeInfo[] ti = (TakeInfo[]) prop.GetValue(importer, null);

        importer.clipAnimations = SetupDefaultClips(ti);
       
        AssetDatabase.WriteImportSettingsIfDirty(objectPath);
        AssetDatabase.SaveAssets();

    }

    static ModelImporterClipAnimation[] SetupDefaultClips (TakeInfo[] importedTakeInfos)
    {
        ModelImporterClipAnimation[] clips = new ModelImporterClipAnimation[importedTakeInfos.Length];

       
        for (int i = 0; i < importedTakeInfos.Length; i++)
        {
            TakeInfo takeInfo = importedTakeInfos [i];
           
            ModelImporterClipAnimation mica = new ModelImporterClipAnimation();
           
            mica.takeName = takeInfo.name;
            mica.firstFrame = (float)((int)Mathf.Round (takeInfo.bakeStartTime * takeInfo.sampleRate));
            mica.lastFrame = (float)((int)Mathf.Round (takeInfo.bakeStopTime * takeInfo.sampleRate));

            if((mica.name.Contains("idle") || mica.name.Contains("Idle") || mica.name.Contains("loop") || mica.name.Contains("Loop") || mica.name.Contains("walk") || mica.name.Contains("Walk") || mica.name.Contains("run") || mica.name.Contains("Run")|| mica.name.Contains("Crawl") || mica.name.Contains("crawl")) && (!mica.name.Contains("Turn") && !mica.name.Contains("turn")))
            {
                mica.loopPose = true;
                mica.loop = true;
                mica.loopTime = true;
            }
            mica.keepOriginalOrientation = true;
            mica.keepOriginalPositionY = true;
            mica.lockRootRotation = true;
            mica.lockRootHeightY = true;
           
            mica.lockRootRotation = true;
           
            clips[i] = mica;
        }
        return clips;
    }

Have you submitted a bug report? :slight_smile: Could you please post the number for me