Hi there, I the ability to batch process fbx animation files and set their rig settings. Is there a way to access these settings through code? I can export the clips names and settings to the fbx format but not sure how to set the rig settings. I want to make sure every animation is set to Humanoid and is using a specific avatar.
The settings I’m most interested in setting through a script are below.
Thank you.
See those lines at the bottom? You need to create your own asset pre / post processor.
I’ve put together a simple post processor. I’m mostly interested in setting the animation type, the avatar def and the root motion node. All of this works great except I get an error 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?
Thanks.
class AnimationEditorPostProcessor : AssetPostprocessor
{
ModelImporter avatarImporter;
Avatar GetSourceAvatar()
{
//get avatar to apply to animations being imported
avatarImporter = assetImporter as ModelImporter;
Avatar avatarObj = (Avatar)AssetDatabase.LoadAssetAtPath("Assets/Art/Meshes/Avatar/Human/Male/HumanMale.fbx", typeof(Avatar));
return (avatarObj);
}
void OnPreprocessAnimation()
{
Avatar sourceAvatar = GetSourceAvatar();
var modelImporter = assetImporter as ModelImporter;
modelImporter.sourceAvatar = sourceAvatar;
modelImporter.animationType = ModelImporterAnimationType.Human;
modelImporter.motionNodeName = "HumanMaleSkeleton/root/root_motion";
modelImporter.optimizeBones = false;
}
}
The error is “Requesting to import non human rig as human”. Does this mean I need to change my export settings for the fbx? I was hoping there would be a way to just automate it in the post processor.
@noahmizrahigala , I just solved a very similar issue!
The reason that you’re getting the error is because Unity imports the model before the animations. Here’s what’s happening with your code:
Unity imports the model rig (as generic) → your Animation preprocessor code sets the animation type of humanoid → Unity tries to import and apply the animation as humanoid but sees that you have a generic rig. Error!
This also explains why it works after applying and refreshing again, because by then the animation type is humanoid, and Unity then imports the rig as humanoid.
Basically, instead of OnPreprocessAnimation, you should be calling OnPreprocessModel. Cheers!