- Home /
Recommendations for Animation Structure/Organization?
Given an imported mesh model with multiple animations, I have seen three different ways of structuring them for use in Unity, and don't know which is best.
The one I first ran into, was Animation Splitting, from the Manual page on Animations. It presumed that the model had one loong animation, which you split up by hand, telling Unity what frames made up each clip. I think I can rule this method out. :)
Method 2: I found while playing with Blender, is to use its Action Editor to create multiple Named Actions. When I imported the model into Unity, each Action became a playable Animation Clip.
Method 3: is of course using multiple model files, again from the Manual page. Each file has a single Animation, with the filename becoming the Animation clip name.
So: what are the consequences of using either of these two methods? In terms of ease-of-use in a script? In terms of project size?
I realize that Unity's documentation uses the multiple-file method, as does, for instance, their Character-Animation Tutorial, etc. Does that mean it's the recommended way, or just how their 3D modeller worked best?
Looking at their tutorial, I see that every file is at least a megabyte. It looks as if, every file includes a copy of the original mesh, which is a lot of duplication. For a project with lots of animations, wouldn't that be prohibitive? Would it be better (using Blender) to store all of the animations in one file, so there's only one copy of the basic mesh?
Are there any downsides to using the single-file, multiple Actions method? Will it be harder in the long run for me to use them, for any reason, in Unity?
Answer by Murcho · Mar 11, 2010 at 01:54 PM
In my previous project we used the first method you listed, however as edits were made frequently it became quite tedious to manually perform the splits every time, until we discovered the AssetPostprocessor Class in the Unity Editor Scripts.
By creating an editor script, you only have to list the splits in a script once, and if any edits are made you simply edit the script, which is simple seeing as they will generally be added to the end of the animation timeline in the asset file.
Here is the guts of the importer script, it isn't too complicated, and once setup an artist should be able to add the extra lines of code required once new animations are added to the single file.
class AnimationPostProcessor : AssetPostprocessor { void OnPreprocessModel() { string assetPath = assetPath; if(assetPath.Contains("nameofmodel")) { ModelImporter modelImporter = assetImporter as ModelImporter; modelImporter.splitAnimations = true; modelImporter.generateAnimations = ModelImporterGenerateAnimations.InRoot;
// Set the number of animations here
int numAnimations = 1;
ModelImporterClipAnimation[] animations = new ModelImporterClepAnimation[numAnimations];
animations[0] = SetClipAnimation("walk", 0, 24, true);
// Add your new animation splits here, simply changing the arguments
// Assign the clips to the model importer to automagically do your splits
modelImporter.clipAnimations = animations;
}
}
private ModelImporterClipAnimation SetClipAnimation(string name, int firstFrame, int lastFrame, bool loop)
{
ModelImporterClipAnimation mica = new ModelImporterClipAnimation();
mica.name = name;
mica.firstFrame = firstFrame;
mica.lastFrame = lastFrame;
mica.loop = loop;
return mica;
}
}
Fill in the blanks, add your splits and away you go. Obviously you can get creative with it so if you have several models with the same animation line put them into a uniquely named folder and search for the folder name before splitting, making it easier across many files.
You're right, I remember reading about this method somewhere, just forgot :) And it has the advantage of being smaller than the multiple-file method Unity seems to prefer. But - first, does your 3D modeller support named Actions? (Blender does) I'm not sure why this Post-processor method would be better than having multiple named Actions/animations in the model file itself. Wouldn't having one gigantic animation get unwieldy to make changes to it?
If Blender has an automated way of doing it, then yes it would probably be better. We were using 3D Studio $$anonymous$$ax for this, and it was the easiest solution we found for our current pipeline.
Within $$anonymous$$ax changing this was quite simple as we could store the animations out in seperate bip files, and then put them together in the biped animation mixer, so it wasn't too unwieldy. Work could then be performed on individual animations if required.
Yes, Blender's Action Editor works great for maintaining separate animation clips in the same model file. I just don't understand why Unity's tutorials use multiple files (taking up megabytes of space). Either a) their 3D modeller doesn't have the capabilities that Blender has (hard to believe), or b) there's some hidden downside to the single-file method, that I just don't know of :) Or possibly c) inertia, they've always done it that way...
$$anonymous$$ultiple files are good for rapid development. You can have your animator working on more and more animations, and your code $$anonymous$$m doesn't need to worry about having to wait for the entire set of animations to be completed. I also think that it may be possible to remove the mesh from the individual files, as there is just animation data you are taking from it, which would reduce the file size dramatically. I haven't tested this however so don't quote me on it. At the end of the day though, different development styles require different techniques, and its good to have options.
@ZanzibarDreams, @$$anonymous$$urcho is right, you should make a new Question. The concept of this site is to have single-focus Questions, with rating of Answers for that Question through voting. If you try to put multiple Questions/Answers in either a comment thread, or in an Answer post, it makes it hard to vote for, search for, etc. If necessary, make a new Question and put a link (the 'globe' button) to this question.
Answer by cmk2901 · Jun 04, 2011 at 08:59 PM
We use the "multiple file" approach, and have found that it works quite well for a few reasons. First, in Unity, you don't have to manually enter the splitting info or create any custom scripts. Second, in the modeling program, it is tedious to rearrange all the animations if, say, you find that your animation requires 30 frames rather than 20.
When you build a player, I think you will find that the only assets included in the build are the ones you use. So, if you have an "idle" version of the mesh that you are including in your scenes, as well as the animation files from multiple files, only the idle mesh and the animation files are included in the player - not duplicates of the same mesh.