Writing a Script to Minimize Retargeting Errors

Hi,

As using 3rd party humanoid animations is such a common thing to do and foot sliding and imprecise animations is such a horrible thing to look at I would like to write a script that minimizes these errors.

The workflow by hand:

  • Edit the avatar that is being used to import the animations (e.g. convert them to humanoid mechanim animations)
  • Save
  • Test the animation on the mesh that you would use ingame
  • Check the errors by looking at them from all directions
  • Repeat until satisfied

I was unable to find a way to edit the Avatar settings of an imported FBX (the prefab representation with the generated avatar attached)

What I found so far:

  • You can build a modified Avatar from an existing one using AvatarBuilder.BuildHumanAvatar. You can then save this Avatar as an asset.
  • HOWEVER: You cannot reference this avatar asset in “Copy From Other Avatar” in the Animation import window. This will result in an error trying to copy over the HumanDescription*
  • I tried overwriting the exisiting auto-generated avatar by using EditorUtility.CopySerialized without success (the function goes through but does not do anything on the asset file)
    EDIT: The copying seems to do something. Loading the asset by script and checking the changed values confirm that they have been saved. It does not show in the editor though)
  • Editing the .meta file of the FBX, which contains the skeleton info is not recognized by the editor even after a restart - EDIT: I does seem to have some effect!
  • You can create human poses using the HumanPoseHandler - this seems like something for runtime use and unable to edit the avatar pose

My Question:

Is it possible in any shape or form to configure the generated Avatar of an imported FBX by script, i.e. the pose used for coversion to mechanim?

In case anyone wonders:

 HumanDescription sourceDescription = sourceAvatar.humanDescription;

// Edit description...

string sourcePath = AssetDatabase.GetAssetPath(sourceAvatar);
ModelImporter modelImporter = (ModelImporter)AssetImporter.GetAtPath(sourcePath);
modelImporter.humanDescription = ownDescription;
modelImporter.SaveAndReimport();