Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by maciekblady · Aug 18, 2016 at 05:18 PM · animationscripting problemeditorfbximporterimport model

Changing default animation type to Humanoid via script

Hello! I'm trying to change default animation type during .fbx import to Humanoid via Editor script using this little piece of code:

     public class ChangeModelToHumanoid : AssetPostprocessor
     {
         void OnPreprocessModel()
         {
             ModelImporter modelImporter = assetImporter as ModelImporter;
             modelImporter.animationType =   ModelImporterAnimationType.Human;
             EditorUtility.SetDirty(modelImporter);
             EditorApplication.SaveAssets();        
         }
     }

While it seems to change the setting properly, Unity is unable to automatically generate avatar for imported animations, displaying following warning:

Required human Bone Hips not found

Is there any proper way to change the dafault import option and still get a working avatar?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Devilwhale · May 17, 2017 at 10:17 PM 0
Share

There seems to be unexposed operations under the hood.

I was going to try and manually convert a avatar using avatarhumanbuilder, however that requires data from a valid humandescription. That still doesn't cover changes to animations clips. Curve properties, etc. There is some hint of the data in the meta after a conversion. I was unable to find anything that works.

I was able to get bone path matching using a ht(humantemlate) file, but the steps to convert property names to humanoid are unknown to me. I don't understand the difference in animation file format before and after the conversion as well. (path -> properyname.x) vs Path.rotate in humanoid animation clip properties.

If the process is not exposed, or needs to be kept private, can we at least get a function to replicate the conversion process. This will make the automation of processing assets for unity into mechanim compatible much easier.

This would also allow for users to custom the automation process on models that don't 100% work.

For example I Converted a $$anonymous$$odel that was missing a foot bone, failed to convert. I would love to be able to add code during the import process to add missing bones.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Devilwhale · May 23, 2017 at 02:51 PM

This is what I ended up using. Using existing avatar as a template.
-Resources have a pre-converted model with the avatar (named as template "Max", "MakeHuman", etc)

-Input folder is where models will be auto imported and converted to humanoid.

 private string[] templates = new string[] {  "Max_", "MakeHuman_"};
     //based on name prefix or if in a folder (Input/Max_/anymodel.fbx) will also work. 
     //matches up it's avatar from one in the resources folder
    
     void OnPreprocessModel()
     {
         if (assetPath.Contains("Input"))
         {
             ModelImporter importer = (ModelImporter)assetImporter;
 
             //Load in the preconfigured avatar from the resources folder
             foreach (string template in templates)
             {
                 if (assetPath.Contains(template))
                 {
                     //Switch to humanoid
                     importer.animationType = ModelImporterAnimationType.Human;
                     //Trim off the underscore
                     string trim = template.Substring(0, template.Length - 1); 
                     //Apply the avatar from the resources folder
                     importer.sourceAvatar = Resources.Load<Animator>(trim).avatar;
                     break;
                 }
             }
             //Log a warning if we didn't find a match 
             Debug.LogWarning("Model prefix does not correspond to any pre-configured humanoid avatar.");
         }
     }
 
     void OnPostprocessModel(GameObject model)
     {
         if (assetPath.Contains("Input"))
         {
             ModelImporter importer = (ModelImporter)assetImporter;
             
             //Add the animator and preconfigure it.
             if (!model.GetComponent<Animator>())
             {
                 model.AddComponent<Animator>();
                 model.GetComponent<Animator>().avatar = importer.sourceAvatar;
                 model.GetComponent<Animator>().applyRootMotion = true;
             }
         }
     }



Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image maciekblady · May 24, 2017 at 05:01 PM 0
Share

Hi @Devilwhale ! Thanks for posting Your solution. I ended up doing almost exactly the same thing as You did. It seems that using a source avatar is the best way to tackle this problem right now (in my case, I also had to use a pre-generated human template file to create human and skeleton descriptions).

avatar image ChristopherGoe · Jan 02, 2019 at 12:00 PM 0
Share

@maciekblady do you $$anonymous$$d posting what you did? Im stuck at the same problem right now and cant seem to fix it, even though i copied the Code from @Devilwhale

avatar image ChristopherGoe · Jan 03, 2019 at 10:32 AM 0
Share

Why do you set the avatar in the postProcessmodel to sourceAvatar again? That doesnt change anything does it? Dont you want to set the Avatar back to the original Avatar which fbx File got imported?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Evaluating animation curves in the Timeline 1 Answer

Is there way to check "Add loop Frame" automatically when FBX importing? 2 Answers

Get current Animation Controller being edited by Animator (In Editor) 0 Answers

Animation is not running, but value is stuck, if Animatori s enabled! 0 Answers

Can I know why I can't control volume of audiomixergroup without exposing parameters? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges