Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Generate avatar from model not working with editor script?

Discussion in 'Editor & General Support' started by ArcticOrca, Jul 14, 2021.

  1. ArcticOrca

    ArcticOrca

    Joined:
    Jul 1, 2017
    Posts:
    2
    Hello, I came here looking for some help with editor scripting.

    I'm trying to make some editor scripts to automate the process of importing multiple .fbx files, and possibly do all of these via batchmode later on.

    I think I've done most of the parts, except for this avatar generation stuff.

    In editor GUI, one would do this by clicking a fbx model file -> Rig -> Avatar Definition -> Create from this Model.

    In my case, I want to do this process fully automated, all by editor scripts.

    I came up with a code below to do this, but I had some problems actually creating this "avatar".

    Code (CSharp):
    1. modelImporter.avatarSetup = ModelImporterAvatarSetup.CreateFromThisModel;
    This does change the Avatar Definition option in the editor, but it doesn't actually create an avatar for the model.

    I looked up the web for hours and found people that had the same problem as I, but it seems they ended up having to do some "manual" task of preparing avatar for individual models.

    (link to one of these posts: https://answers.unity.com/questions/1231161/changing-default-animation-type-to-humanoid-via-sc.html)

    However, since it's been years after this posts were made, I wonder if there is a way to resolve this problem in newer versions of unity?

    Thank you in advance.
     
  2. ArcticOrca

    ArcticOrca

    Joined:
    Jul 1, 2017
    Posts:
    2
    Solution found.

    After setting modelImporter.avatarSetup, call assetimporter.SaveAndReimport, and it will do the job.