• 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
11
Question by Ross_S · Oct 02, 2014 at 03:58 PM · animationtriggermecanimboolean

Mecanim Trigger getting stuck in 'TRUE' state

So, I have some triggers in the Animation Controller - these work fine most of the time... I call SetTrigger() from the code and they trigger once and then are immediately false - waiting to be triggered again. But occasionally i notice that the anim is auto-happening when it should be waiting for the trigger. When i check in the Animation Controller I can see a little tick next to the trigger indicating it's constantly turned on... behaving like a 'bool' - ... this seems to be a Unity bug... anybody got any ideas ? Thanks

Comment
Add comment · Show 7
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 Jesse_Pixelsmith · Oct 11, 2014 at 04:37 AM 0
Share

I'm seeing this as well for my melee attack cycle, definitely seems like a Unity bug, nothing that I'm doing seems like it should cause this.

avatar image Sylker Jesse_Pixelsmith · Apr 06, 2015 at 07:57 AM 0
Share

Yeah, it seems to be a bug. I am stuck with that too and using bool ins$$anonymous$$d. Gotta set it to false all the time =/

avatar image Mochnant Jesse_Pixelsmith · Jun 23, 2015 at 08:21 PM 0
Share

I've also encountered this bug in 5.1.1f. I was not able to find an open ticket in the issue tracker on it.

avatar image LordDarkon76 Jesse_Pixelsmith · Dec 15, 2015 at 04:56 PM 0
Share

It isnt a bug,

The trigger is an auto managed bool, if you set a trigger it will stay true until a transition is triggered.

avatar image bitstrider LordDarkon76 · Feb 24, 2016 at 07:19 AM 0
Share

not just any transition either...it must be one that uses the trigger as a condition

avatar image meat5000 ♦ · Nov 19, 2014 at 01:38 PM 0
Share

This probably comes down to just a few things.

Ti$$anonymous$$g! Polling states can often result in a mismatch of ti$$anonymous$$g meaning the animation is looped or fired as the off condition is not set in time or has been totally missed.

Not Clearing a Set item. http://docs.unity3d.com/ScriptReference/Animator.ResetTrigger.html

Exit Time parameter - This is notorious for messing up even the simplest of Anim chain ti$$anonymous$$gs.

avatar image $$anonymous$$ · Feb 13, 2015 at 04:30 PM 0
Share

I've also had a similar experience although the ResetTrigger did not help unless I put it into a check for the next state.

 if (Animator.GetCurrentStateInfo(0).nameHash = _defaultState)
     {
        Animator.ResetTrigger("AnimationYouWantToReset");
     }

9 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by D-Sparky · Dec 08, 2016 at 06:45 AM

Try this. It helped me with both problems. http://answers.unity3d.com/questions/667486/progress-bar-not-showing-in-animator-tab.html

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
0

Answer by yourecrippled · Mar 17, 2017 at 02:25 PM

animator controller > click on state > uncheck "write defaults"

I did this to all states in my animation controller. It worked for me.

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
0

Answer by Tomas_Kok · Oct 30, 2017 at 07:59 PM

As far as I understand a Trigger is represented as a boolean internally. If the Trigger is fired, the boolean is set to true. As soon as the transition enters, the boolean is set to false. If, for any reason, the transition is not entered, the boolean/Trigger will remain true. The first time the transition is checked again, the Trigger is still true and will fire, checking the transition and setting itself to false.

A common scenario: You have a Grounded, Jumping and Airborne state and 2 parameters: a boolean isGrounded and a Trigger Jump. The transition from Grounded to jump requires the Jump Trigger to be triggered, from Grounded to Airborne the IsGrounded boolean to be false and from Airborne to Grounded the IsGrounded boolean to be true. When you jump, you trigger the Jump Trigger and you also set IsGrounded to false. When you fall from a platform, you only set IsGrounded to false.

What can happen when you jump (by triggering the Jump Trigger but also setting IsGrounded to false) is that both transitions from Grounded to the Jump and to the Airborne state fulfill their conditions. When the Aiborne state is chosen, the Jump Trigger will remain true (since the transition to Jump is not entered). When you land on the ground again and IsGrounded is set to true, the Airborne state transitions to the Grounded state. Because the Jump Trigger is still set to true, the Grounded state immediately transitions to the Jump state and sets the trigger to false.

The above example can simply be fixed by setting the priority of the transition to Jump higher than the transition to Airborne (by selecting the Grounded state and dragging and dropping the transition to Jump above the transition to Airborne). In a more general case, be sure when multiple transitions could happen and either change their priority, set the Trigger to false explicitly in code or rethink the design.

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
0

Answer by Ash-Blue · Nov 14, 2017 at 10:51 AM

Some good answers here, but ultimately the issue is you might have to force Animator.ResetTrigger in some situations. Here is a code snippet that will let you do a reset from an Animator state so you don't have to write any extra code. To apply it click your animator state you want to trigger the reset -> In the inspector click Add Behavior -> Add the ResetTrigger script. This is a best practice since it confines your Animator logic instead of letting it wander around your scripts. Making it very easy to go back and remove this from the Animator later if you want to.

     public class ResetTrigger : StateMachineBehaviour {
         [Tooltip("The trigger you wish to reset")]
         [SerializeField]
         private string _trigger;
 
         private void OnStateEnter (Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex) {
             animator.ResetTrigger(_trigger);
         }
     }
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
  • ‹
  • 1
  • 2

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

43 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

Related Questions

Mechanim Trigger Issue 1 Answer

NetworkAnimator: SetBool vs. SetTrigget? 1 Answer

Basic animation key press 0 Answers

Mecanim Trigger event on specific frame of an animation 4 Answers

Trigger Animation Instantly? 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