How do I optimize my animation controller? 400+ animations in one controller.

The main character of my game can aim and shoot in any of 8 different directions, multiplied by being able to do that from jumping, standing, and crouching, and ledge grabbing, and additionally can turn from left to right, with an in-between turn animation, and unique-nonflipped animations on each left/right facing, for every single one of those aiming directions.

The controller is massively bloated and massively buggy right now, and its basically impossible to debug or manage. How do I fix this? I don’t really understand how to use blend trees or sub-state machines…

maybe switch to a code based state change using animator.play

check this article

Please don’t do this, it’ll get even harder to debug. You have so many states that you’ll have a hard time finding the actual line of code that’s not working as intended - and you won’t even have a visual aid like this state machine.

I think you either need Sub-State Machines or Override Controllers. I can’t make out the text on your states, so I can’t tell you which one. You say that you don’t understand them, but I think the manual is pretty self-explanatory: https://docs.unity3d.com/Manual/NestedStateMachines.html

You’re basically just collapsing states into a “folder”. And instead of transitioning to the first state of your action you transition into the folder. This doesn’t change the functionality at all, it’ll just make things clearer visually (and logically). From the way your tree looks alone I’d say that the entire lower part should be one sub-state machine, then the center, center-left, center-right, top, top-left and top-right. Just a guess, but by the way you laid them out it seems like these are the logical blocks of your controller.
Or you could have one sub-state machine per looking direction. So one “folder” that manages left, one for right and so on.

Alternatively I’m thinking that an Override Controller might work, but that really depends on your project. This basically lets you replace individual animations without changing the controller itself. So you could have an animator controller that does everything you need for when you’re looking to the right. And then you could create overrides for all of the other directions. Since the transition logic should be the exact same, you could just replace the animations. Now all you’ll need to do in code is change the animator controller when the character changes directions.

1 Like