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 are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice
  4. Join us on Thursday, September 29, for a day with Unity's SRP teams here on the forum or on Reddit, and discuss topics around URP, HDRP, and the Scriptable Render Pipeline in general.
    Dismiss Notice

Writing a Script to Minimize Retargeting Errors

Discussion in 'Animation' started by Forberg, Sep 18, 2022.

  1. Forberg

    Forberg

    Joined:
    Oct 27, 2018
    Posts:
    14
    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:

    1. Edit the avatar that is being used to import the animations (e.g. convert them to humanoid mechanim animations)
    2. Save
    3. Test the animation on the mesh that you would use ingame
    4. Check the errors by looking at them from all directions
    5. 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?
     
    Last edited: Sep 18, 2022
  2. Forberg

    Forberg

    Joined:
    Oct 27, 2018
    Posts:
    14
    In case anyone wonders:

    Code (CSharp):
    1.  HumanDescription sourceDescription = sourceAvatar.humanDescription;
    2.  
    3. // Edit description...
    4.  
    5. string sourcePath = AssetDatabase.GetAssetPath(sourceAvatar);
    6. ModelImporter modelImporter = (ModelImporter)AssetImporter.GetAtPath(sourcePath);
    7. modelImporter.humanDescription = ownDescription;
    8. modelImporter.SaveAndReimport();
    9.  
     
unityunity