I have hundreds of 2D animations that will represent unique characters in my (procedurally generated) game. For the sake of ease of creation/import and optimisation, I was wondering whether there is a smarter way to make all these animations work without having to make 1000 animation controllers each with 1 state and 1 animation file connected to it.
For instance:
- 1 animation controller with 1000 states? (still requires me to make add all states and all animation files)
- swapping frames through code? (building a custom editor window to make that easy?)
- ā¦
Any experiences?
1 Like
Always glad to help if I can but I donāt use Animator or Legacy Animations.
It should work about the same way Iād guess as far structuring them go.
First, of course, make one group (your Animator in this case) per character type. Then you can make all of the individual animations for that character.
i have many animations too, and the same questions
you can use an āanimation override controllerā to reuse controllers with different animations i guess. but i did not use that since my controllers are simple anyway
not sure this is the best way but ya i made a controller for each type of mob
and inside i use simple blend trees to select a random animation available to that mob type

and in addition to all these mobs each mobs has many (up to 12 or more skins) to do that i found the easiest tho maybe not most elegant is this @20min mark
so you only need to make each animation once
Thanks for linking the talk, rakkarage! It seems like you did exactly what I want to avoid: making controller and animation files for every character. I am literally going to have 1000+ characters, so I am not planning on taking that same route.
I found a solution today. I wrote the following component:
using UnityEngine;
using System.Collections;
public class OverrideAnimations : MonoBehaviour
{
public AnimationClip idleAnimation;
public AnimationClip walkAnimation;
public void Start ()
{
Animator animator = GetComponent<Animator>();
AnimatorOverrideController overrideController = new AnimatorOverrideController();
overrideController.runtimeAnimatorController = animator.runtimeAnimatorController;
if(idleAnimation != null)
overrideController["OverrideAnimationIdle"] = idleAnimation;
if(walkAnimation != null)
overrideController["OverrideAnimationWalk"] = walkAnimation;
animator.runtimeAnimatorController = overrideController;
}
}
Every character I have gets an Animation Controller that contains a general structure that most of my characters have. For instance, I have characters that only have an idle animation, and so the Animation Controller attached to it has 1 state called āIdleā with an empty animation attached to that state called āOverrideAnimationIdleā. If I fill in the idleAnimation variable in the Inspector of the script shown above, the clip called āOverrideAnimationIdleā will be replaced with the idleAnimation clip.
Another example would be of characters that walk, and stand still every once in a while. An different Animation Controller handles these two states, but I only need one Animation Controller using my script for all the characters that walk and stand still, but look different.
1 Like