transition priority Any State vs specified state

Consider the following Mecanim transitions: A->B and [Any-State]->B. The animation controller is in state A and the conditions for both transitions are true.

Which transition becomes active and according to what criteria?

From my understanding, you can change the priority of transitions leaving a specified state. You just need to select the state and reorder the transitions in the list. However, the [Any-State]->? transitions do not appear in this list, only in the [Any State] list.

From my experience so far, A->B takes priority over [Any-State]->B in a situation where both are valid.

Some of the comments bring up that you should probably try to avoid having both transitions altogether. However, in a scenario where you want to have tailored settings for a specific transition, and other settings for all other transitions, the direct alternative can cause a transition explosion.

Consider the following real scenario: I have 9 A-actions (attacks) and 8 B-actions. All attacks and B-actions (17 total) can transition to one another. Thus, the number of transitions between them is the combination “17 choose 2” times 2 (bidirectional). C(17,2)*2 = 272. Managing and tuning 272 transitions is unfeasible.

What is the solution to control this complexity? Use Unity 5 with sub-state machines. The new animation controller allows collapsing transitions by having generic transitions to a state, and transitions from entry state. This way we can have two sub-state machines, one for attacks, one for B-actions. Transitions to these two sub-state machines are made generic, instead of to specific states, and we add self transitions to each of the sub-state machines. See pictures for example setup.

Now with Unity state machine transtions, one option available to you is to add a statemachine that sets a boolean when entering the state, for example “preventanystate” when transiting to A and sets it to false when exiting the state.

Then in the transition from Anystate->B, this boolean is checked to be false. This ensures that B->A must be played instead.