• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by PabloJMartinez · Jul 08, 2014 at 10:15 PM · animationanimatorbugmecanim

Mecanim CrossFade transition interruption issue

Imagine that you have a idle state running and you have a run forward state. So, if you press W you trigger a transition from idle to run forward with CrossFade and if you stop pressing W you trigger a transition from run forward to idle.

Here comes the problem, the transition takes X time to complete, if you only push W once the character should stop the transition and come back to the idle state, but Mecanim thinks that he's still in idle because the transition didn't finished to go from one state to the next.

So, how I'm supposed to make a responsive movement system through CrossFade if you can't abort a transition when you desire to?

So, you can't come back to the origin state when you are CrossFading to the next because Mecanim believes that you are still on the origin state when, visually, you are not (you are between the two).

Is this a bug, or a desired behavior? If it's a bug, is this gonna be fixed some time soon? If it's the desired behavior, I'm not supposed to use CrossFade in that way?

Thanks.

EDIT1: This is an example of what I want to achieve -> https://www.youtube.com/watch?v=eXQJvZF6AjY

EDIT2: I'm attaching a clear example of the problem: http://www.mediafire.com/download/35bt1484bjlw3b0/Mecanim_CrossFade_Problem.rar

Press W to trigger an Animator.CrossFade from Idle to Walk Forward, you'll that if you press it only once it will keep walking forward until the transition is finished, so you CAN'T interrupt the transition to come back to the origin state until the transition is ended (Idle in this case).

Also, if you press F you'll triger a manual CrossFade to Idle, and, as you can see it won't work until the Idle to Run Forward transition is ended. This is just to make the problem more clear.

Comment
Add comment · Show 8
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Jul 09, 2014 at 12:48 PM 1
Share

Exit Time parameter and Atomic Checkbox. Both accessible by clicking on the transition arrow in Animator window.

avatar image PabloJMartinez · Jul 09, 2014 at 01:22 PM 0
Share

I don't know what that have to do with the problem exposed here?

avatar image meat5000 ♦ · Jul 09, 2014 at 01:37 PM 0
Share

.Play and .CrossFade were popular with the old system but there are better ways in Animator.

There are better ways to control the Animator system without falling back on Legacy methods; Parameters.

Have you actually looked at the items mentioned in my last comment? Have you actually set up a State-$$anonymous$$achine in Animator?

avatar image meat5000 ♦ · Jul 09, 2014 at 01:44 PM 0
Share

O$$anonymous$$AY! I just looked at your project. You State-$$anonymous$$achine has NO transitions in it.

Right click a state, click $$anonymous$$ake Transition and click on the next state. You will need transitions To and From your States. When you have done this, refer to my first comment.

avatar image PabloJMartinez · Jul 09, 2014 at 02:01 PM 0
Share

It doesn't have transitions because I decided to do it fully through scripting with CrossFade.

I tried to use a State-$$anonymous$$achine but I have the same problem and it's a mess to manage for me. Why to force people to use that if you already had full control through scripting with Legacy?

How can you make a smooth transition but be able to make a transition back to the origin BEFORE the first transition is finished if you need to?

Thanks for the help.

(I'm talking about this: https://www.youtube.com/watch?v=eXQJvZF6AjY)

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by PabloJMartinez · Jul 09, 2014 at 03:35 PM

So, the thing is that it seems it's impossible to do this through scripting with CrossFade, ok.

So, the solution is to use Blend Trees so you can control the "transitions" manually through scripting with full control with one or two variables. I have used a 2D Freeform Directional Blend Tree because I need multiple speeds in multiple directions, but you should use whichever fits your problem better.

EDIT: As pointed out by gelu23, it's in fact possible to do this through CrossFade by explicitly setting the normalizedTime to 0.

So... if you want to use a state-machine go for Blend Trees and if you want to use CrossFade use normalizedTime 0.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gelu23 · Jul 22, 2014 at 08:15 AM 2
Share

To do this through scripting you have to set normalizedTime to 0 (or any other value different from float.NegativeInfinity). like: CrossFade(stateName, transitionDuration, -1, 0);

avatar image
1

Answer by turdann · Jun 23, 2015 at 12:57 PM

You should mark your transition as "Interruption Source: Next State". This way, the transition could be interrupted by trantisitons of the next state (run forward).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by MartinTV · Jan 06 at 05:38 AM

Waaaay late to the party here, 8yrs, so might not be relevant BUT I cached the current state (on the 3rd layer), called rebind, then used animator.play to force the character into the animation they were just in with the normalized time value for the cached sate.

     void RebindAndRestoreAnimator()
     {
         // Cache info
         Animator anim = PlayerInfo.playerAnim;
         AnimatorStateInfo info = anim.GetCurrentAnimatorStateInfo(3);
         // Rebind then resetinfo
         anim.Rebind();
         anim.Play(info.shortNameHash, 3, info.normalizedTime);
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Mecanim issue: Twitching when blending into blendtrees 1 Answer

Is it possible to make empty, passing state in mecanim? 3 Answers

Anima 2d 4 direction character 2 Answers

Mecanim: get animation duration from Animator state name 0 Answers

Edit AnimationClip during runtime from script 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges