- Home /
Multiple Animation Controllers
Currently in my 2D sprite-based melee combat game, all of the player's animations are stored in one Animator Controller. This "works" but I'm finding that the number of states and transitions is growing very large, mainly because I have several different weapon types (sword, spears etc.) each with their own movesets.
For example, any given weapon will have:
Attack 1 2 and 3 (basic 3-hit combo)
Heavy Attack 1 2 and 3
Guard
Parry
Idle (as in a little idle animation specific to that weapon, like playing with a dagger by tossing it between your hands)
This is 9 animations for each weapon type. Currently I have 4 weapon types, but I'm planning to add more. This is why my animator controller is getting large and unwieldy.
So I was thinking: For each weapon type, could I give it its own Animator Controller, and then just play the corresponding animation for that animator controller from within the player controller code instead of from the default player Animator Controller? So when you equip a weapon, it could set some reference in the player controller (e.g. "weaponAnimController"), and then when the player presses the attack button, it just plays whatever the current "attack" animation is from the current weapon Animator Controller. (I have a system already that basically does this but it's quite convoluted). This would also enable me to more easily add special weapons, e.g. with unconventional movesets.
I guess I'm asking this just to sanity check it; I don't know much about animating, but I feel like this would be a cleaner and more modular way of handling multiple weapon animations rather than having them all in the same controller with loads of states and transitions all over the place. So:
- Would this work, i.e. can a gameobject be animated by multiple different controllers at the same time, or will this cause issues? Because e.g. the regular player animator controller might be in the "idle" state, but then it's possible to also be in an "attacking" state in the weapon animator controller.
- If it's not going to work for whatever reason, is there a different way of doing this, maybe within the same controller, e.g. using layers, which I'm not familiar with (yet)?
- Would having separate animation controllers for each weapon type impact performance/memory (noticeably) at all? It's not a huge concern for me but it is something I'm aware of.
I don't actully know, but I would think you could do just what you descriped by adding animation layers.
I know it is mostly important for 3D, but don't be afraid to use animation layers. You can easily make a layer just for combat, and have all attack types easily organized.
Did you ever resolve this issue? I have a similar problem
Answer by cypriano450 · Jan 06, 2020 at 07:32 AM
@Nephtis I think this can help you solve this problem...
https://docs.unity3d.com/Manual/AnimatorOverrideController.html
Your answer
Follow this Question
Related Questions
2D Animation does not start 1 Answer
Setting animator parameter on a single instance of a prefab sets the parameter for all instances 3 Answers
Object not moving after changing animator parameter 1 Answer
2D Character getting a weapon. Changing it's sprites/animations 0 Answers
Animator warning in editor, animation is preventing script from working 1 Answer