Search Unity

Transitioning with CrossFade into a state which is also transitioning makes the state stuck

Discussion in 'Animation' started by dreasgrech, May 24, 2017.

  1. dreasgrech

    dreasgrech

    Joined:
    Feb 9, 2013
    Posts:
    205
    I am currently doing a transition between two Animator states using the CrossFade method. This is because I need to arbitrarily transition between State A and State B while keeping the current normalized time. So if I transition from State B at 0.3 normalized time, it needs to transition into State A's 0.3 normalized time, and I'm doing this CrossFade in a StateMachineBehaviour.

    But what I have noticed is that if I CrossFade from State A to State B into a point in State B where it has another transition out of the state, the animation gets stuck in State B for a certain duration.

    For example, I CrossFade at 0.9 normalized time from A to B but B also has another transition out of it with an exit time of 0.8f. What happens is that when crossfading into B, the Animator gets stuck into B for a while before actually carrying out that transition which happens at 0.8f.

    Has anyone encountered a similar issue?
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    If my memory is correct I remember reading about similar issues with transitions into a state that is at that time transitioning out and/or looping which is the same as transitioning into another state. But I believe this was solved either by an engine update (5.3?) or a solution was provided by one of the Unity developers.
    Consider looking back a ways in the animation sub-thread for similar issues others experienced. Also may consider looking directly at @Mecanim-Dev post history, as my memory (is bad) but I seem to remember him being involved in those discussions.
    Hope that helps point you towards a solution.
     
  3. dreasgrech

    dreasgrech

    Joined:
    Feb 9, 2013
    Posts:
    205
    Thanks for your reply @theANMATOR2b

    I'm on Unity 5.5.3p3 and I did actually go through @Mecanim-Dev post history until December or so but I didn't see anything related or I must have missed it.

    The reason I wanted to do this is because I had specific non-loopable states (both blend trees) which needed to transition between them arbitrarily but keeping the same normalized time, so the destination state starts at the current time of the source state instead of at the start of the animation. The problem occurs because both of these states have transitions with exit time (normalized) less than 1, and when one of them crossfades into the other state at a point in time where the latter state should be in its exit transition, the state gets stuck for a little while.

    To work around this, I ended up going with a root 1D Blend Tree containing two other blend trees (the two states I mentioned above, the ones I am transitioning between) and then added a parameter to control which of the inner blend trees to have active, so that the root blend tree controls "the transitions" between the two states rather than using CrossFade.
     
  4. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Oh - cool! That solution seems - 'different' , and interestingly the answer wasn't 'code' - but I'm glad you solved.
    Yeah - I should have clarified - I think I remember this discussion - very similar to your writing - even in your last post - a ways back, like going back into late early 2016. But anyway - you found a non-code solution to the problem. That's pretty rare. Glad you solved. I'm keeping this thread as a saved solution in my tips/tricks folder. ;)