Search Unity

Force Sub state machine to transition to other state / sub state machine under certain conditions

Discussion in 'Animation' started by Hoshiqua, Feb 7, 2019.

  1. Hoshiqua

    Hoshiqua

    Joined:
    Jul 22, 2016
    Posts:
    77
    Hey !

    Working on my game I encountered a problem with my player animator state machine.

    Long story short, the player can be idle / advancing, attacking or regenerating. There are currently 3 animations for attacking that are chained using a trigger. I want the player to be able to very quickly transition from attacking to either idling or regenerating.

    Now, my problem could technically be solved by putting everything in the same layer and making ALL the transitions. Problem is, it seems really dirty to do so, and it's going to be a lot of work to keep track of everything, especially if I add more animations / states.

    So what I have set up right now is a sub state machine that contains all the attacking animations and their chaining. Whenever they stop chaining they switch to a "default" transition that leads out of the sub state machine and back to the idling animation, which has a transition to the "regenerating" animation that gets activated with a boolean.

    My game is quite fast paced so the time it takes to finish the current attack animation, transition to idling then immediatly transition to regenerating is very noticeable and sometimes it leads to my character not playing the right animation at the right time.

    What I'd like to do (but I don't know if it's possible) is set it up so that whenever I'm regenerating, and inside the attacking sub state machine, the main state machine immediately exits from that sub state machine and transitions to the regenerating animation, whatever animation it's currently doing.

    Is such a thing possible or do I need to make all the transitions by hand ?

    Thanks in advance !