Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Mecanim Exit Time transition with additional condition

Discussion in 'Animation' started by Marble, May 2, 2014.

  1. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,245
    Let's say I want State 1 to transition to State 2 when ExitTime is after 0.5 and int parameter "State Index" is 0. Unless I am mistaken, this is impossible in Mecanim.

    If "State Index" becomes 0 when ExitTime is 0.51, then the whole animation state will have to loop once before the transition executes, because ExitTime must be exact.

    Can anyone help me think of a workaround for this stupefying limitation?
     
  2. MrEastwood

    MrEastwood

    Joined:
    Dec 9, 2013
    Posts:
    18
    JWheater likes this.
  3. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,245
    Thanks for your reply, MrEastwood. Doesn't this then mean that there needs to be a script component added for every transition, if the required ExitTime and StateIndex varies per state? Nightmare!
     
  4. MrEastwood

    MrEastwood

    Joined:
    Dec 9, 2013
    Posts:
    18
    If this is a condition you need regularly i would not use a boolean but a float instead. In this float your helper scripts stores the normalizedTime that you ironically get from the animator itself. The trick is that you can now use normalizedTime as a condition in each transition that needs it. This differs from using Exit Time, because the Exit Time condition is only met at that exact time, but our normalizedTime variable can be used with the "greater than" and "less than" evaluations.
     
  5. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,245
    Ooh, clever. So you're feeding the animator a value that it already technically knows about but can't normally use ("normalizedTime").

    It makes me peeved that ExitTime can't simply have a Greater / Less / Equals pulldown like any other float condition, but this is a great, simple, and very silly solution. Thanks!
     
  6. wechat_os_Qy07SM4foXYQW4vn0nREyGjTQ

    wechat_os_Qy07SM4foXYQW4vn0nREyGjTQ

    Joined:
    Aug 5, 2021
    Posts:
    2
    Thank you, Marble and MrEastwood This really saved my ass though seven years later
     
    MrEastwood likes this.
unityunity