Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Changing the state's exit transition settings at runtime

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

  1. WiktorWasowski

    WiktorWasowski

    Joined:
    Dec 23, 2012
    Posts:
    15
    Hello!

    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.