I'm having a speed/memory problem when adding animations via script.
I have a character model that has 100+ animations spanning around 1800 frames. I've had trouble with Unity occasionally deleting all my animation clips when I reimport models, so I decided to add the animation via script, using animation.AddClip(...).
So now I have around 100 animation.AddClip(...) calls inside that character's Awake method, and on top of that I have up to 6 of these characters in a single scene.
The problem is that, on a 3GS, the game takes around 8 seconds to load those clips per character and also takes an addition 4-5MB, which kills older devices.
One way I could attempt to fix this is by just adding the animation clips in the Asset Import window like Unity expects you to, but I don't want to do this unless it's going to actually fix things, and there's also the side issue of us having a few different character models, all with the same animation frames; so I'd rather not have to duplicate everything for each one, but will do if it's our only option.
So my question is, will adding the clips via Asset Import fix my problem (and why?) and is there any better way to manage my situation.
Thanks in advance.
If you don't have the performance issues when the clips are added through the inspector, you could try to add them using an editor script so you don't have to redo that every time when losing the connections after an import.
But, 100+ animations? It's quite a lot, don't know what you're doing but possibly you could reduce the amount by blending animations (separating the lower-body from the upper-body animations).
I had that problem on Android. The way I solved it was to not use animation compression and only call the animations (by script) as they were needed (duplicate, then delete the imported animations).
The script had to use Mathf.ABS rather than just Input.GetAxis and attached the script to the Tank rather than using Search(“Player”). I also moved all the animations, after duplicated, to their own folder away from the models folder.
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
else if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.1)
rather than just
if (Input.GetAxis("Vertical")) > 0.1)
I posted a script yesterday that would handle all the animations and allow the private var so you can select each animation for each event here: How to start in animating model? - Unity Answers