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 inovax09 · Sep 29, 2015 at 03:35 AM · animation2dmecanimdelay

Cant get rid of animation delay in Mecanim

Hey, guys! I am trying to get rid of delay when my gameobject goes from state FireFlyStrafe back to state FireFlyIdle. I checked a lot of issues with animation delay but still can't make my own work as planned. Here's code I use to control states and pictures of transitions between states. I am flipping strafe animation in my code.

 using UnityEngine;
 using System.Collections;
 
 public class FiryFlyAnimCtrl : MonoBehaviour {
 
     private Animator anim;
     bool facingRight = true;
     bool set = false;
 
     void Start()
     {
         anim = GetComponent<Animator>();
     }
 
 
     void Update()
     {
 
         float move = Input.GetAxis("Horizontal");
        
         anim.SetFloat("SpeedHorizontal", Mathf.Abs(move));
 
         if (move > 0 && !facingRight)
         {
             Flip();
         }
         if (move < 0 && facingRight)
         {
             Flip();
         }
     }
 
     private void Flip()
     {
         facingRight = !facingRight;
         Vector3 scale = transform.localScale;
         scale.x *= -1;
         transform.localScale = scale;
     }
 }

issue1.png (75.6 kB)
issue2.png (73.3 kB)
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

2 Replies

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

Answer by RChrispy · Sep 29, 2015 at 10:50 AM

Hey since you disabled "Has exit time" this should work.

Under your conditions try set less and greater 0 so it will start exactly != 0 and not 0.1.

And why do you use: Mathf.Abs Is there a special reason for absolute values?

 anim.SetFloat("SpeedHorizontal", Mathf.Abs(move));

If it still has a delay i would make a bug report to unity about this!

ps: I find it better to declair variables that you always use out of scope.

 float move = 0

I would declair it outsite of the Update() scope because of memory alloc. And garbage collect thingis :)

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 inovax09 · Sep 29, 2015 at 07:34 PM 0
Share

@Dev6_RC thanks for reply! I have solved this problem recently by triggering animation straight with buttons input not horizontal input. I haven't yet figured out why horizontal input makes state transition delayed but I am working on it.

avatar image RChrispy inovax09 · Sep 30, 2015 at 06:57 AM 0
Share

I think you can just use :

 Input.GetAxisRaw("Horizontal"); ins$$anonymous$$d of Input.GetAxis("Horizontal");

And this should fix a lag! ;)

avatar image Lyje · Aug 31, 2017 at 03:47 PM 0
Share

I know this is old, but the "Has exit time" tip helped me so it's still useful!

That said, declaring move outside of Update has no benefit, and has potential downsides. floatis a value type so gets created on the stack* - no GC alloc. And it's generally good practice to give vars the absolute $$anonymous$$imum scope required to do their job. Otherwise you can end up modifying state when you didn't mean to.

Of course, if it was a reference type, declaring as a member and re-using to avoid GC alloc is totally valid - but that's an optimisation you should make later. Optimisations like that generally come at the cost of making your code less straightforward (i.e. harder to read, understand, maintain and refactor) and should only be made when you need them.

*yes, I know, not strictly always 100% true, but when it's not, it's because the compiler knows better than you so don't try to second-guess it.

avatar image
0

Answer by uberalles · Sep 30, 2015 at 12:49 AM

Click on the transition, you'll see two boxes. The top (and left most) is the state you're transitioning from and the lower one it the target state. Drag the bottom box all the way left until it matches the top one and makes sure under (just below 'Has Exit Time') that Transition Duration is set to zero as well.

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

6 People are following this question.

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

Related Questions

Animator idle minimal delay 0 Answers

Select Animations Freezing on First Frame 1 Answer

How do you check to see if an animation is playing in a Sub-State machine? 0 Answers

mecanim dynamic animation choice 0 Answers

Is there a way to optimize animators? 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