- Home /
Question by
AtsumuOno · Jun 12, 2017 at 09:14 AM ·
animationimport modelassetpostprocessor
Bone of human avatar is out of reference with asset post processor
Hello.
I tried to run the script automatically when importing fbx file. The things I want to do are below.
Optimize game objects
Change AnimationType to Human
Material assignment
Generation of prefab
So, I implemented it using AssetPostProcessor.
using UnityEngine;
using UnityEditor;
using System.Collections;
public class ModelImportProcessor : AssetPostprocessor
{
const string ModelPath = "Path...";
void OnPreprocessModel()
{
var assetPath = assetImporter.assetPath;
var importer = assetImporter as ModelImporter;
importer.optimizeGameObjects = true;
importer.extraExposedTransformPaths = new string[]{Extra Transforms to Expose...};
importer.meshCompression = ModelImporterMeshCompression.Low;
importer.isReadable = false;
importer.optimizeMesh = true;
var desc = importer.humanDescription;
var bones = desc.skeleton;
desc.skeleton = bones;
importer.humanDescription = desc;
}
void OnPostprocessModel(GameObject go)
{
var assetPath = assetImporter.assetPath;
if (assetPath.Contains(ModelPath))
{
var importer = assetImporter as ModelImporter;
importer.animationType = ModelImporterAnimationType.Human;
}
}
}
However, running this script will cause problems. The avatar is broken.
Human avatar becomes invalid, and all bones are out of reference.
The cause seems to be caused by changing AnimationType to Human in the script. Deleting the corresponding code will work normally (however, prefab with an AnimationType of Generic will be created)
importer.animationType = ModelImporterAnimationType.Human; // commented out
Please show the way to solve it.
Thank you.
スクリーンショット-2017-06-12-145201.png
(15.0 kB)
スクリーンショット-2017-06-12-145209.png
(55.4 kB)
Comment