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 are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice
  4. Join us on Thursday, September 29, for a day with Unity's SRP teams here on the forum or on Reddit, and discuss topics around URP, HDRP, and the Scriptable Render Pipeline in general.
    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,254
    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:
    19
    JWheater likes this.
  3. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,254
    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:
    19
    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,254
    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. DeepDeepWoe

    DeepDeepWoe

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