Search Unity

Fix mask button in the animation's inspector

Discussion in 'Animation' started by patoffspyder, Jan 22, 2014.

  1. patoffspyder

    patoffspyder

    Joined:
    Jan 22, 2014
    Posts:
    8
    Hi guys,

    Our animator here is having a problem.
    On one model, when he imports animations, he is getting an error: Mask does not match hierarchu. Animation migh not import correctly. Next to it there is a Fix Mask button. When he presses this button, everything is fixed, but there is 200 animations on this character so he needs to do this on every animations and sometimes when he imports a new one the mask become broken again.

    Do you know how to fix this or if there is an assetPostProcessor script I could make for him? Haven't found a way to replicate this Fix Mask button via scripting yet.

    Thanks a lot!
     
  2. turbojoys

    turbojoys

    Joined:
    Jan 8, 2014
    Posts:
    10
    i also see this on my animator, but my question is, does this warning even matter? why would this even show up when we properly configure the avatar in the first place?

    coz with this warning on, i dont see any incorrectness in my character animations.

    this sort of things really bugs people, while everything seems to be working fine, still unity keeps warning you

    can someone plz come forth and clear the smoke for us
     
  3. klajntib

    klajntib

    Joined:
    Dec 3, 2013
    Posts:
    1
    It warns you that the animation might not import correctly and that is exactly what happened in our case.
    Some new joints wouldn't animate and always stayed on 0,0,0.

    Did anyone discover a way to do a Fix Mask operation on all the animations at once?
     
  4. Johra

    Johra

    Joined:
    Aug 26, 2013
    Posts:
    1
    *bump* This would be great! Multi object fix mask, plz :)
     
  5. WilliamLeu

    WilliamLeu

    Joined:
    Jul 27, 2012
    Posts:
    10
    *bump

    I got this problem from changing the fbx hierarchy and overwriting the previous fbx files ( 50 facial animations and 30 movement animations). The meta files have too much information embedded in them (curves/events) and too many file links to them to just clear all the files and restart from scratch with newly generated meta files.

    I'd just ignore them if we didn't need them to be fixed to properly blend our animations.
     
  6. Rosie-Posie

    Rosie-Posie

    Joined:
    Nov 20, 2013
    Posts:
    54
    Hey guys, running into a similar issue in Unity 4.6.

    I'm using the "Copy from Other Mask" option and I get this weird behavior where, if I do changes to the Master mask, they wont go trough to any of my animations unless I go back and re-select the mask. It's as though it saves the info the first time I set it and then never checks the master for any changes.

    It kinda defeats the purpose of copying the mask in the first place...

    Has anybody found a solution to applying a mask to several animations all at once?

    Cheers
    Rosie
     
  7. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    191
    you can use this script to automatically fix all masks, I've tested it in Unity 4.7, it assumes the default behavior of using "Mask Definition: Create From This Model" with all transforms selected.

    http://pastebin.com/pRG9EnEc

    Code (CSharp):
    1. //saves you from agonizing manual clicking "Fix Mask" on each user-created clip,
    2. //when you have updated/edited the original FBX changing the skeleton hierarchy
    3.  
    4. //drop this in your Scripts/Editor folder,
    5. //select FBX's and right click context menu Fix Animation Masks
    6. //tested on Unity 4.7
    7.  
    8. //minor update, sets all transforms of the avatarMask to active (assuming you are just using 'Mask Definition Create From This Model' with all transforms active (Default behavior)
    9.  
    10. using UnityEditor;
    11. using UnityEditorInternal;
    12. using UnityEngine;
    13. using System;
    14. using System.Reflection;
    15.  
    16. public class FixMask
    17. {  
    18.     [MenuItem("Assets/Fix Animation Masks")]
    19.     private static void Init()
    20.     {
    21.         foreach( UnityEngine.Object obj in selection )
    22.         {
    23.             string path = AssetDatabase.GetAssetPath( obj );
    24.             ModelImporter mi = AssetImporter.GetAtPath(path) as ModelImporter;
    25.  
    26.             Type modelImporterType = typeof(ModelImporter);
    27.  
    28.             MethodInfo updateTransformMaskMethodInfo = modelImporterType.GetMethod("UpdateTransformMask", BindingFlags.NonPublic | BindingFlags.Static);
    29.  
    30.             ModelImporterClipAnimation[] clipAnimations = mi.clipAnimations;
    31.             SerializedObject so = new SerializedObject(mi);
    32.             SerializedProperty clips = so.FindProperty("m_ClipAnimations");
    33.            
    34.             AvatarMask avatarMask = new AvatarMask();
    35.             avatarMask.transformCount = mi.transformPaths.Length;
    36.             for( int i=0; i<mi.transformPaths.Length; i++ )
    37.             {
    38.                 avatarMask.SetTransformPath(i,mi.transformPaths[i]);
    39.                 avatarMask.SetTransformActive(i,true);
    40.             }
    41.            
    42.             for( int i=0; i<clipAnimations.Length; i++ )
    43.             {
    44.                 SerializedProperty transformMaskProperty = clips.GetArrayElementAtIndex(i).FindPropertyRelative("transformMask");
    45.                 updateTransformMaskMethodInfo.Invoke(mi, new System.Object[]{avatarMask, transformMaskProperty});
    46.             }
    47.             so.ApplyModifiedProperties();
    48.  
    49.             AssetDatabase.ImportAsset(path);
    50.         }
    51.     }
    52. }
     
    Stokes likes this.
  8. Stokes

    Stokes

    Joined:
    Aug 26, 2014
    Posts:
    2
    Wow, this saved me. Thanks so much!