Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Editor script take clips from FBX apply to Animator

Discussion in 'Animation' started by coshea, Feb 5, 2021.

  1. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    319
    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:
    Code (CSharp):
    1. importedModel = ModelImporter.GetAtPath(path) as ModelImporter;
    2. numClipsModel = importedModel.clipAnimations.Length;
    3. importedClips = new ModelImporterClipAnimation[numClipsModel];
    The animator states:
    Code (CSharp):
    1. ChildAnimatorState[] ch_animStates = stateMachineLayer.states;
    2. foreach (ChildAnimatorState curState in ch_animStates){
    3. AnimatorState thisState = curState.state;
    4. //thisState.motion = ???
    5. }
    I'm not sure if I'm missing something obvious, nothing useful showing up on Google either.

    Thanks!
     
  2. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    319
    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...

    Code (CSharp):
    1. var assetRepresentationsAtPath = AssetDatabase.LoadAllAssetRepresentationsAtPath(path to fbx);
    2. foreach (var assetRepresentation in assetRepresentationsAtPath) {
    3.     AnimationClip _animClip = assetRepresentation as AnimationClip;
    4.     if (_animClip != null) {
    5.        // do something with the clip
    6.     }
    7. }
     
    neputanu likes this.