Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Changing the state's exit transition settings at runtime

Discussion in 'Animation' started by WiktorWasowski, Feb 24, 2017.

  1. WiktorWasowski


    Dec 23, 2012

    I have an Animator Controller for my humanoid characters that has Left Hand Attack and Right Hand Attack states. These play a punch animation if there is no weapon equipped. If the character puts a weapon in any of these slots, an Override Controller is created that puts a different animation (weapon specific) into that slot (or both). This has worked well for me, because the Animator Controller stays simple and easy to navigate and change, but recently a problem arose.

    I also have other states that need a specific transition from the Attack sub state machine. Mostly the Dodge state. The Attacking animation shouldn't be able to be interrupted by Dodge, but the player needs to be able to Dodge as soon as the weapon reaches its maximum distance in a swing (so still rather early in the animation). So Attack -> Dodge needs to have Exit Time on and have the transition itself starting in a very precise point of the Attack animation.

    Now the problem is that when I change any of the Attack animations using the Override Controller, the transition doesn't end up in a correct place, because all attack animations are different. As a result, either the player is able to dodge too early and interrupt the swing too early, or needs to wait too long before they can dodge. Both cases are bad and unwanted.
    I know about the CrossFade methods, but they seem to only enable me to setup the enter transition, not the exit transitions, so I can't use them with Attack. Technically I could probably use CrossFade with the Dodge state if the current state is Attack and set the transition depending on the current weapon equipped, but isn't there any better solution? Partially moving the animation logic from the animator to a script seems like an ugly thing to do... Especially, that Dodge may not be the only animation that needs to be able to transition from Attack at a specific time.