Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Trying to automate animation settings and getting "Requesting to import non human rig as human"

Discussion in 'Scripting' started by noahmizrahigala, Nov 2, 2022.

  1. noahmizrahigala

    noahmizrahigala

    Joined:
    Mar 8, 2021
    Posts:
    20
    I've put together a simple post processor that runs when animators export their animation into the unity project. I'm setting the animation type, the avatar def and the root motion node. All of this works great except I get an error "Requesting to import non human rig as human" which requires a manual update. If I hit "update" and then "apply" the file is exactly as I'd like it to be settings wise.

    Any advice on how to avoid the manual update and automate the process?

    Thanks.

    Code (CSharp):
    1. class AnimationEditorPostProcessor : AssetPostprocessor
    2. {
    3.     ModelImporter avatarImporter;
    4.     Avatar GetSourceAvatar()
    5.     {
    6.         //get avatar to apply to animations being imported
    7.         avatarImporter = assetImporter as ModelImporter;
    8.         Avatar avatarObj = (Avatar)AssetDatabase.LoadAssetAtPath("Assets/Art/Meshes/Avatar/Human/Male/HumanMale.fbx", typeof(Avatar));
    9.         return (avatarObj);
    10.     }
    11.     void OnPreprocessAnimation()
    12.     {
    13.         Avatar sourceAvatar = GetSourceAvatar();
    14.         var modelImporter = assetImporter as ModelImporter;
    15.         modelImporter.sourceAvatar = sourceAvatar;
    16.         modelImporter.animationType = ModelImporterAnimationType.Human;
    17.         modelImporter.motionNodeName = "HumanMaleSkeleton/root/root_motion";
    18.         modelImporter.optimizeBones = false;
    19.     }
    20. }
     
  2. mzahmbie

    mzahmbie

    Joined:
    Mar 16, 2013
    Posts:
    3
    Hey, I was running into this same issue. The problem comes that the Model/Rig are imported before the animations, so when you modify the Avatar during OnPreprocessAnimation it's not setting the data until after that has run. If you put your avatar modifying code into OnPreprocessModel instead this should work as you're expecting.