Editor script take clips from FBX apply to Animator

I’m working on an Editor script called from editor gui that will take an input fbx file, read out all the clips and an animator file, cycle through to set those clips to be used on Animator states.

The bit that I’m having trouble with is converting ModelImporterClipAnimation to a motion clip used by the animator states.

Here is how I get the clips from the fbx:

importedModel = ModelImporter.GetAtPath(path) as ModelImporter;
numClipsModel = importedModel.clipAnimations.Length;
importedClips = new ModelImporterClipAnimation[numClipsModel];

The animator states:

ChildAnimatorState[] ch_animStates = stateMachineLayer.states;
foreach (ChildAnimatorState curState in ch_animStates){
AnimatorState thisState = curState.state;
//thisState.motion = ???
}

I’m not sure if I’m missing something obvious, nothing useful showing up on Google either.

Thanks!

For the sake of anyone else looking for this later, here’s what I did in the end. ModelImporter is good for getting a list of default clips and imported clip data, but I couldn’t get the actual clip out to put into the animator. So used LoadAllAssetRepresentationsAtPath to load all the asset parts with the fbx then go through and store the clips…

var assetRepresentationsAtPath = AssetDatabase.LoadAllAssetRepresentationsAtPath(path to fbx);
foreach (var assetRepresentation in assetRepresentationsAtPath) {
    AnimationClip _animClip = assetRepresentation as AnimationClip;
    if (_animClip != null) {
       // do something with the clip
    }
}
1 Like