Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Ghosthowl · Apr 30, 2014 at 10:01 PM · mecanim

Mecanim: normalizedTime is sometimes wrong

Hello,

I am trying to achieve something incredibly simple but it has taken the past 2 days to get something workable that would have been doable in a few seconds with the legacy system. I am trying to have a method that plays an animation, waits until the animation has completed, then stops. I have figured out how to do this using some non ideal ways but I want to know how to do this like this.

     public IEnumerator PlayOnceUntilFinished(string paramName)
     {
         animator.CrossFade(tempName, 0.25f, 0, 0.01f);
         yield return null;
         if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime < 0.95f)
         {
             Debug.Log("Current is right");
             while (animator.GetCurrentAnimatorStateInfo(0).normalizedTime < 0.95f)
             {
                 //Debug.Log(animator.GetCurrentAnimatorStateInfo(0).normalizedTime);
                 Debug.Log("Attempting current...");
                 yield return null;
             }
         }
         else if (animator.GetNextAnimatorStateInfo(0).normalizedTime < 0.95f && !(animator.GetCurrentAnimatorStateInfo(0).normalizedTime < 0.95f))
         {
             Debug.Log("Next is right");
             yield return new WaitForEndOfFrame();
         }
         else if (animator.GetNextAnimatorStateInfo(0).normalizedTime < 0.95f && animator.GetCurrentAnimatorStateInfo(0).normalizedTime < 0.95f)
         {
             Debug.Log("Both are right.");
         }
         Debug.Log("Animation completed.");

Here is what is happening - sometimes 'Current is right' fires, as well as it's while statement (which works beautifully) but most of the time 'Next is right fires' and skips the current 'if' statement completely. I need to be able to wait and know when the animation is completed due to my state machine on my AI character so triggers will not work for me (also because of my system, triggers fail a lot of times to show the animation because the machine will continue without knowing is it still happening)

I am almost positive the solution to the issue is to some how wait long enough until the next state (which should be the current) has transitioned into the current, but how would I go about knowing this or figuring it out? The solution must be so simple but I for the life of me cannot see it after so much time spent. Thank you for any and all help!

PS: Here is how I currently do it:

         if (this.animator.GetCurrentAnimatorStateInfo(0).IsName("Base Layer." + mecanimActionName))
         {
             // Avoid action until animation is finished
             this.playingAnimation = true;
             if (debug)
                 Debug.Log("Beginning Animation");
 
         }
         else if (this.playingAnimation)
         {
             this.playingAnimation = false;
             // Animation has just completed!
             playCounter++;
             if(playCounter == playCount)
             {
                 if(debug)
                     Debug.Log("Played Animation " + playCounter + " times.");
                 EndAction(true);
             }
             else
             {
                 if(trigger)
                     animator.SetTrigger(mecanimActionName);
                 //StartCoroutine(PlayOnce(mecanimActionName));
                 StartCoroutine(PlayOnceUntilFinished(mecanimActionName));
             }
 
         }
Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with the wrist bones during conversion to Mecanim's skeleton. 0 Answers

Animator set current animation normalized time. 1 Answer

Mecanim, my object deforms when I put my own animations! 1 Answer

Distortion in blending animations of walk 0 Answers

creating new animations with mecanim 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges