x


How do you add AnimClips at import time correctly?

Hello Iam slowly making progress on getting my animations into unity but I have an issue that I have to reimport the fbx file for my created clips to show up. For example in this grab you can see the project shows two anim clips but on the right in the inspector the correct 4 clips are shown: alt text But if I then reimport the asset the project shows the correct set of clips alt text Iam making and adding the clips at import time through the AssestPostProcessor class thus:

void OnPostprocessModel(GameObject go) { Debug.Log("PostProcess " + go.name);

BaseData[]  data = go.GetComponentsInChildren<BaseData>(true);

for ( int i = 0; i < data.Length; i++ )
    data[i].PostLoad(go);

// Deal with anims
ModelImporter modelimporter = assetImporter as ModelImporter;

modelimporter.clipAnimations = new  ModelImporterClipAnimation[0];

for ( int j = 0; j < data.Length; j++)
{
    if ( data[j].GetType() == typeof(AnimationControl) )
    {
        AnimationControl acon = (AnimationControl)data[j];

        ModelImporterClipAnimation[] anims = modelimporter.clipAnimations;

        ModelImporterClipAnimation[] newanims = new ModelImporterClipAnimation[anims.Length + acon.clips.Count];

        anims.CopyTo(newanims, 0);

        for ( int a = 0; a < acon.clips.Count; a++ )
        {
            ModelImporterClipAnimation clip = new ModelImporterClipAnimation();
            clip.firstFrame = acon.clips[a].StartFrame;
            clip.lastFrame  = acon.clips[a].EndFrame;
            clip.loop   = acon.clips[a].Loop;
            clip.wrapMode   = acon.clips[a].Wrap;
            clip.name   = acon.clips[a].Name;
            newanims[anims.Length + a] = clip;
        }

        modelimporter.clipAnimations = newanims;
        acon.SortAnimsOut();
    }
}

}

So can anyone help into why I have to reimport for the clips to show up correctly, there must be a step Iam missing somewhere. Thanks Chris

more ▼

asked Mar 11 '10 at 09:22 AM

SpookyCat gravatar image

SpookyCat
436 5 5 12

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I posted a script we used in a previous project to perform the animation splits on import here.

Reading through your code, there are a few things I'm not sure of as they are referencing custom classes that haven't been provided (eg AnimationControl), so I can't really comment on what is exactly happening there, however I can say that my script worked reliably so it might be worth looking at to try and fix your issue.

One thing that did stick out however is you are using OnPostprocessModel(), and I am using OnPreprocessModel(). Possibly the editor doesn't see or save the changes until the second import as they are happening after the import, not prior to the import.

more ▼

answered Mar 12 '10 at 11:47 PM

Murcho gravatar image

Murcho
2.7k 12 23 53

Thank you for the help, yeah your code looks very similar problem is I need to do this on post process as Iam using custom Max plugins that export the data to the fbx for the various anim clips and that data is passed in the user properties. I shall have a go today so see if adding some test clips prior to OnPostProcess gives me what I need and if so I guess Ill have to have a slight rethink on maybe storing the data in a anim file or something. Thank you again.

Mar 13 '10 at 10:24 AM SpookyCat

Sure enough the code works fine in OnPreprocessModel, so a slight massaging of my system and all should be ok, thankyou for your help again. Chris

Mar 13 '10 at 08:05 PM SpookyCat
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3777
x970
x558
x63
x51

asked: Mar 11 '10 at 09:22 AM

Seen: 1417 times

Last Updated: Mar 11 '10 at 09:22 AM