- Home /
Changing FBX clips start/end/wrap on import (Legacy, OnPreprocessAnimation, c#)
I got no bites in the forum. Hoping someone here can help me.
Hey all, I've been grinding my brain against this for half a week, tried solving it several ways but to no avail.
I have written an animpicker and exporter (fbx massager really) in maya that splits a large animation file into named takes, and adds string attrs to an object that my editor script then parses into a dictionary (animSettings is a list of dicts in the code below) with anim names, starts, ends, and wrap details. Eventually I'll add events as well but for now I'm trying to get new fbx exports to replace the unity anim list completely (including wrap mode which fbx doesnt recognize)
The debug.log at the bottom out the correct values, which are read from the modelImporter clips, but the inspector doesnt reflect the changes that the script has made. Do I need to overwrite something with the modelImporter object in order to see the changes saved?
Thanks in advance for any assistance you can provide. I'm an OOP noob and really dont grok this lower level stuff yet.
void OnPreprocessAnimation()
{
var modelImporter = assetImporter as ModelImporter;
//Debug.Log("PreProcessAnim");
modelImporter.clipAnimations = modelImporter.defaultClipAnimations;
foreach (ModelImporterClipAnimation anim in modelImporter.clipAnimations)
{
foreach (Dictionary<string, string> thisAnim in animSettings)
{
if (anim.name == thisAnim["name"])
{
anim.firstFrame = Int32.Parse(thisAnim["start"]) + 1; //im throwing in a +1 just to see the values change
anim.lastFrame = Int32.Parse(thisAnim["end"]) - 1; //will remove these values when working
switch (thisAnim["wrap"])
{
case "Default":
anim.wrapMode = WrapMode.Default;
break;
case "Clamp":
anim.wrapMode = WrapMode.Clamp;
break;
case "ClampForever":
anim.wrapMode = WrapMode.ClampForever;
break;
case "Loop":
anim.wrapMode = WrapMode.Loop;
break;
case "Once":
anim.wrapMode = WrapMode.Once;
break;
case "PingPong":
anim.wrapMode = WrapMode.PingPong;
break;
default:
break;
}
Debug.Log("Found the clip for " + anim.name + ". Start:" + anim.firstFrame.ToString() + ". End:" + anim.lastFrame.ToString() + ". Wrap:" + anim.wrapMode.ToString());
}
}
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Same Animator, different clips for different objects. 0 Answers
Can I make animations snap to a frame? 1 Answer
Animator run 2 animations at once 1 Answer