So I have the following situation that cannot be easily handled with a Mecanim State Transition chart: I have a high number of animations for the same character in my game, let's say about 50. Let's call them Attack 1, Attack 2, ....Attack 50, just for illustration purposes. So far I am able to easily add them as States to an Animation Controller and add Transitions for them from my Idle state. So far so good, I can perform each animation individually and that works just fine.
Here comes the problem though. Next, I want to be able to perform multiple animations one after another, as soon as the previous one ends, with just one button click. For example, when the player hits the A button, I want the character, who is already in Idle state, to do Attack 1 --> Attack 2 --> Attack 3 --> Idle. I figured out I could do that by creating a Transition from Idle to Attack 1 with a Boolean parameter that is set to True when the player hits a certain button, then another Exit Time Transition from from Attack 1 to Attack 2, then the same (Exit Time) from Attack 2 to Attack 3, and finally from Attack 3 to Idle. Basically I created a Transition loop (in the image below Attack 1 is "punching_2", Attack 2 is "roundhouse_kick_2 0", and Attack 3 is "leg_sweep_2 0", and the Transitions in the loop are highlighted in Blue):
While that works fine, it's a problem when you have a lot of animations and need to be able to perform pretty much every permutation of length 4 or less. For example, what if I need to perform the following animation combinations?
- Attack 1 --> Attack 2
- Attack 2 --> Attack 1
- Attack 1 --> Attack 2 --> Attack 3
- Attack 1 --> Attack 3 --> Attack 2
- Attack 2 --> Attack 1 --> Attack 3
- Attack 2 --> Attack 3 --> Attack 1
- Attack 3 --> Attack 1 --> Attack 2
- Attack 3 --> Attack 2 --> Attack 1
- Attack 1 --> Attack 2 --> Attack 3 --> Attack 4
- etc. etc. etc.
I think you see where I am going with this. If I were to attempt to create a State Transition loop like the one in the image above for every single combination in the Animator Controller editor, things would get out of hand, and flat out impossible to keep track of, very fast.
So here comes my question: is there a way to add and delete Transitions programmatically so I can create loops like the one above for the particular animation combination I need on the fly? Let's say I want to perform the combination Idle --> Attack 20 --> Attack 34 --> Attack 9 --> Attack 11 --> Idle. I would then create the necessary Transition between the desired States in script and run them upon a button hit. After that I would delete the Transitions.
If that is not possible, how else can I handle the situation I described above?