Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 PersianKiller · Jul 25, 2017 at 10:21 AM · animationanimatorupdatefixedupdatecondition

Should we check animation condition in Update or FixedUpdatE?

I know we should get inputs in Update and do physics stuff in FixedUpdate.but it's my code I don't Know that I should put it in Update or FixedUpdate.

public void RunAnimation(){

     animator.SetFloat ("Speed",Mathf.Abs( GetComponent<Rigidbody2D>().velocity.x));
 }
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

3 Replies

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

Answer by Bunny83 · Jul 25, 2017 at 11:04 AM

It's better to use Update. You should avoid FixedUpdate as much as possible. If you have a framerate drop for some reason it doesn't help when you have many heavy things inside FixedUpdate. Animations are mainly a visual thing so it's best to have it updated with the visual update rate. Even when the velocity occasionally does not change between two Update calls it won't really hurt. Though at a low frame rate you will get several FixedUpdate calls per Update call. However updating the animation settings several times during one visual update makes no sense.

FixedUpdate should only be used for continuously added forces. Applying a single impulse force (like a jump) can and should be done in Update instead. Almost everything can be done in Update. FixedUpdate is only used in some rare exceptions that involve phyics.

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
2

Answer by tanoshimi · Jul 25, 2017 at 12:33 PM

Your question title asks where to check animator conditions. You should do that in LateUpdate(), since that occurs after the internal animation update in each loop. See https://docs.unity3d.com/Manual/ExecutionOrder.html for more info.

Comment
Add comment · Show 3 · 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 PersianKiller · Jul 25, 2017 at 12:56 PM 0
Share

so you say after the next frame We should check conditions? like this

if (input.getkey(keycode.Space)){

animator.SetBool("JU$$anonymous$$P",true);

}


I think we will lose current frame.

avatar image tanoshimi PersianKiller · Jul 25, 2017 at 01:05 PM 0
Share

No, that's not checking an animator state, that's checking input and setting animator state.

avatar image PersianKiller · Jul 25, 2017 at 01:32 PM 0
Share

yes,you're right, Thanks.

avatar image
0

Answer by highpockets · Mar 04 at 08:37 PM

If you need to start an animation based on something that occurs within FixedUpdate() which I need for various reasons, a good approach is to just create an animation control class like this I reckon:

     public class AnimationController : MonoBehaviour
     {
         [SerializeField]
         private Animator _animator;
 
         private bool _isAwaiting = false;
         private int _triggerCount;
 
         private List<(string name, bool value)> _bools = new List<(string name, bool value)>();
         private List<(string name, float value)> _floats = new List<(string name, float value)>();
         private List<string> _triggers = new List<string>();
 
         public void SetAnim(string name, bool value)
         {
             if (_bools.FindIndex(x => x.name == name) == -1)
                 _bools.Add((name, value));
 
             if (!_isAwaiting)
                 StartCoroutine(RunAnimations());
         }
 
         public void SetAnim(string name, float value)
         {
             if (_floats.FindIndex(x => x.name == name) == -1)
                 _floats.Add((name, value));
 
             if (!_isAwaiting)
                 StartCoroutine(RunAnimations());
         }
 
         public void SetAnim(string name)
         {
             if (_triggers.IndexOf(name) == -1)
                 _triggers.Add(name);
 
             if (!_isAwaiting)
                 StartCoroutine(RunAnimations());
         }
 
         private IEnumerator RunAnimations()
         {
             _isAwaiting = true;
 
             yield return new WaitForEndOfFrame();
 
             _bools.ForEach(x => _animator.SetBool(x.name, x.value));
             _floats.ForEach(x => _animator.SetFloat(x.name, x.value));
             _triggers.ForEach(x => _animator.SetTrigger(x));
 
             _bools.Clear();
             _floats.Clear();
             _triggerCount = _triggers.Count;
             _isAwaiting = false;
 
             yield return new WaitForEndOfFrame();
 
             if (_triggerCount != 0 && _triggerCount <= _triggers.Count)
             {
                 for (int i = 0; i < _triggerCount; i++)
                 {
                     _animator.ResetTrigger(_triggers[i]);
                 }
                 _triggers.RemoveRange(0, _triggerCount);
                 _triggerCount = 0;
             }
         }
     }

And then just call SetAnim for the relevant animations..

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.

Follow this Question

Answers Answers and Comments

171 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

Related Questions

Parent and child repositioning 0 Answers

How to play animation clip after the conditon is finished? 1 Answer

Animator dont transition to self or any sub state 2 Answers

2 Different animations with 2 different update modes? 0 Answers

Unity showing "animator" component instead of the "animation" component 2 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