Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by Will_Croxford · May 02, 2018 at 11:12 AM · animationanimatorstatewaitlength

Animator.GetCurrentAnimatorStateInfo(0).IsName("FallOffBed") unexpectedly returns false

Hi, I am using Animator.Play to play animation, then want to measure exact time of this clip, before executing next line in a coroutine.

I checked other answer here, but tried implement with no success so far as follows:

         priestAnimator.Play("FallOffBed");
 
         int baseIndex = priestAnimator.GetLayerIndex("Base");
 
         print("baseIndex is " + baseIndex);
         print("long expression IsName FallOffBed is " + priestAnimator.GetCurrentAnimatorStateInfo(baseIndex).IsName("FallOffBed"));
         print("long expression IsName Idle is " + priestAnimator.GetCurrentAnimatorStateInfo(baseIndex).IsName("Idle"));
         print("long expression IsName Base.Idle is " + priestAnimator.GetCurrentAnimatorStateInfo(baseIndex).IsName("Base.Idle"));
         print("long exp normalizedtime is " + priestAnimator.GetCurrentAnimatorStateInfo(baseIndex).normalizedTime);
         print("both concat with andand is " + (priestAnimator.GetCurrentAnimatorStateInfo(baseIndex).IsName("Base.FallOffBed") &&
             priestAnimator.GetCurrentAnimatorStateInfo(baseIndex).normalizedTime < 1.0f));
 
         while (priestAnimator.GetCurrentAnimatorStateInfo(baseIndex).IsName("Base.FallOffBed") && 
             priestAnimator.GetCurrentAnimatorStateInfo(baseIndex).normalizedTime < 1.0f)
         {
             yield return null;
         }
         // above NOT producing delay or doing anything now! so measure length animation clip at moment guess 4 seconds
         yield return new WaitForSeconds(4);

My console output from above debugging lines is:

 baseIndex is 0
 long expression IsName FallOffBed is False
 long expression IsName Idle is True
 long expression IsName Base.Idle is True
 long exp normalizedtime is 1.919069
 both concat with andand is False

My animation plays fine, I have Write Defaults off so it keeps same position after playing once. I'm new still, so confused a bit what is going on and how GetCurrentAnimatorStateInfo and normalizedTime are working here exactly?

Another answer here from 2015 suggests using animation.clip.length seems simpler, which I think means adding an Animation component to the object to get the reference to animation, but this is legacy component as I understand, so not really supposed to do that now? I am willing to spend time learning 'proper' way of doing things if possible!

NB I hacked with yield return new WaitForSeconds(4); for now as you can see, but this is not proper way, thanks.

Comment
Add comment · Show 1
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 Will_Croxford · May 03, 2018 at 09:10 AM 0
Share

Hi, sorry if comment is overdetailed but in case clearer, this seems to indicate animation is in the State Idle after executing priestAnimator.Play("FallOffBed") - but from other answer on here, and also my own expectation, I was expecting animation to be in the state FallOffBed as soon as this line is executed - I see here normalizedTime is returning the number of times current animator state has played (which here is returning the number of times Idle state played before priestAnimator.play executed, so here it indicates Idle has played 1.9 times (I pressed keys to execute this coroutine pretty quickly after game started). So I think the key problem might be my misunderstanding somewhere about GetCurrentAnimatorStateInfo - honestly grateful for any comment, suggestion or idea thanks, I'm a beginner!

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

223 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

How do I make the transition between two states in the "Animator" happen instantly? 3 Answers

How to get fileID information so i can just edit Mecanim Animator through script? 2 Answers

Animator does not play Animation on object 1 Answer

Easier way of creating transitions in the animator? 1 Answer

Is it possible to make empty, passing state in mecanim? 3 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