- Home /
Question by
rmccabe82 · Feb 13, 2015 at 09:03 AM ·
assetbundleanimationclipassetdatabasehumanoid
Set animation clip humanoid
Hi,
I am creating an asset bundle on the fly by importing assets from a given folder. One of the assets is an fbx file, which contains an animation clip. I need to set the IsHumanMotion flag to try, so I use the AnimationUtility.SetAnimationType function to do this. All works great! I try to save using EditorApplication.SaveAssets etc. But when I reload the asset, it tells me IsHumanMotion = false. What am I doing wrong. Here's a code snippet:
// If this is an fbx asset, do the following
if (lowerfn.Contains(".fbx"))
{
// SET HUMAN ON FBX AND COMMIT!
var importer = (ModelImporter)ModelImporter.GetAtPath(localPath); // e.g "Assets/Body.fbx"
importer.animationType = ModelImporterAnimationType.Human;
EditorUtility.SetDirty(importer);
EditorApplication.SaveAssets(); // this does save the change to the fbx itself, but I need it commited on the clip.
Log("Set model to humanoid via the model importer and saved");
// Load the asset.
Object[] tObjects = AssetDatabase.LoadAllAssetsAtPath(localPath);
// Animation clip object to be searched for in the fbx file.
Object animClip = null;
// Search the objects within the fbx file for the clip (named the same name as the bundle id).
foreach (var item in tObjects)
{
Log("Searching for clip - this object name = " + item.name);
// We know the animation clip has the same name as the bundle id. So pick it out using that match.
if (item.name == bundleid)
{
Log("Found animation clip! Setting to humanoid");
animClip = item;
// Set the clip to humanoid.
AnimationUtility.SetAnimationType((UnityEngine.AnimationClip)animClip, ModelImporterAnimationType.Human);
Log("Clip set to humanoid: " + ((UnityEngine.AnimationClip)animClip).isHumanMotion);
EditorUtility.SetDirty(animClip);
EditorApplication.SaveAssets();
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
// At this point, if I reloaded the asset and got the clip, is human motion would be false again!
// Stop the for loop.
break;
}
}
// Set T = to animation clip, so it is then added to the list.
if (animClip != null)
t = animClip;
}
else
{
// Load the asset.
Object tObjects = Resources.LoadAssetAtPath(localPath, typeof(T));
if (tObjects != null)
t = tObjects;
}
Thanks for help in advance!!
Comment