AssetDatabase.ImportAsset() on Animations of ModelImporter doesn't work

Recent update of Unity 4.3 got me to make an editor of auto-masking weapon bone(since Keep additional bones option has been removed). and I could set Mask - Definition as ‘Copy From Other Mask’ and Source as a new made ‘Avatar Mask’ with the weapon bones checked. but I didn’t make it because AssetDatabase.ImportAsset() didn’t work.
To be exact, Mask is the only thing AssetDatabase.ImportAsset() can apply. (Even firstFrame of ModelImporterClipAnimation can be applied with the method!!! )

                                ModelImporter modelImporter = AssetImporter.GetAtPath(strPath) as ModelImporter;

                                if (modelImporter != null)
                                {
                                    if (modelImporter.clipAnimations.Length == 1)
                                    {
                                        ModelImporterClipAnimation importer = modelImporter.clipAnimations[0];
                                        if (importer != null)
                                        {

                                            importer.firstFrame = 2;
                                            AvatarSetterPostProcessor.foundAvatarMask = foundAvatarMask;
                                            AvatarSetterPostProcessor.strPath = strPath;
                                            importer.maskType = ClipAnimationMaskType.CopyFromOther;
                                            importer.maskSource = foundAvatarMask;

                                            ModelImporterClipAnimation[] newAnimations = new ModelImporterClipAnimation[1];
                                            newAnimations[0] = importer;

                                            modelImporter.clipAnimations = newAnimations;
                                            AssetDatabase.ImportAsset(strPath, ImportAssetOptions.ForceSynchronousImport);
                                            
                                        }

                                    }

                                }

I noticed the same behavior in 5.1 and in 5.2.1p2. The documentation says that ModelImporterClipAnimation.maskNeedsUpdating should become true when ModelImporterClipAnimation.maskType is changed to CopyFromOther. http://docs.unity3d.com/ScriptReference/ModelImporterClipAnimation-maskNeedsUpdating.html This is not the case. I guess, that's the reason why this ImportAsset does not import the right mask.

1 Answer

1

I said something weird. I should’ve said “Mask is the only thing AssetDatabase.ImportAsset() can not! apply”