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
2
Question by QuaintShanty · Jan 03, 2016 at 09:05 AM · c#animationanimatormecanimanimator controller

What is the proper way to wait for an Animator Controller to update?

I've been noticing a slight problem with this block of code after doing some debugging. It was actually my initial thought when I saw something was wrong. Apparently, it seems that SetTrigger() waits a frame or longer before finally transitioning to the new state. Which kind of sucks in this situation.

Here's a little explanation: NullState is the Idle state and baseAttack is the state it should transition to before calling WaitForSeconds(). This script is suppose to wait the length of baseAttack before performing some other actions within the method.

The print statement below, before I added WaitForEndOfFrame(), would usually print True|False|0.3, After adding WaitForEndOfFrame(), it sometimes prints False|True|1 (the desired result) and then, at random, it will sometimes print True|False|0.3.

The Issue: The print statement isn't consistent and it doesn't seem to be waiting for the transition, after SetTrigger() is called, to move to the next state. In short, it's not fast enough (or to be even more precise, I'm most likely ignorant to this subject and I'm doing something terribly wrong)!

 public IEnumerator PlaySkillAnimation(string name)
 {
     animator.SetTrigger(name);
 
     animator.SetFloat("movementSpeed", 0);
 
     yield return new WaitForEndOfFrame(); // new code added in to finally discover that it 'helps' some
 
     print(animator.GetCurrentAnimatorStateInfo(0).IsName("NullState") + "|" + animator.GetCurrentAnimatorStateInfo(0).IsName("baseAttack") + "|" + animator.GetCurrentAnimatorStateInfo(0).length); // just some debugging
 
     yield return new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length);
 }

Comment
Add comment · Show 6
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 CesarNascimento · Jan 08, 2016 at 12:33 PM 0
Share

How are the settings for your transition between states? Exit time and so on.

avatar image QuaintShanty CesarNascimento · Jan 09, 2016 at 06:06 AM 0
Share

@CesarNascimento: I've been fiddling with the exit times of each of them quite a bit. Here's what they currently look like:

STATE: NullState

TRANSITION: NullState -> baseAttack

STATE: baseAttack

TRANSITION: baseAttack -> NullState

avatar image CesarNascimento QuaintShanty · Jan 09, 2016 at 06:06 PM 0
Share

In baseAttack->NullState, set Exit time to 1, I think it'll work.

Show more comments
Show more comments

1 Reply

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

Answer by CesarNascimento · Jan 10, 2016 at 05:10 AM

That's pretty weird. I usually get problems like these when, for some reason, my Triggers aren't resetting by themselves, so I have to use ResetTrigger manually.

Anyway, I think you'll be able to get what you want by using a State Machine Behaviour. If you want to do something just as the animation ends, just use the OnStateExit. See https://unity3d.com/learn/tutorials/modules/beginner/5-pre-order-beta/state-machine-behaviours for more.

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 QuaintShanty · Jan 11, 2016 at 11:52 AM 1
Share

I used the State $$anonymous$$achine Behaviour to resolve the issue. Thanks again.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

why I have to anim.getComponent in update() function when I had done in Start () function 2 Answers

Animation Mecanim - Parts of model displaces after animating 0 Answers

Mecanim: get animation duration from Animator state name 0 Answers

unity freezes when running sprinting animation 0 Answers

How to get length of animation in Mecanim? 1 Answer


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