Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

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:
    70
    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 !