Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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
4
Question by Berendirith · Jun 05, 2015 at 05:01 PM · animatortrigger2d animation

Animator: Trigger not reseting, bug?

alt text

i was following the 2D roguelike training....The guy said the trigger is almost like boolean, but it reset to default after click. in my case, my trigger is exactly what boolean does. how to fix this? I'm using unity 5.0.2f1 personal

screen-shot-2015-06-05-at-233633.png (15.9 kB)
Comment
Add comment · Show 2
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 Smaika · Jun 05, 2015 at 11:34 PM 0
Share

are you sure you are not calling the trigger every frame

avatar image Berendirith · Jun 06, 2015 at 02:21 AM 0
Share

what you mean? when I compile the game with animator open so I can click the animation to animate the object, it change to other state as long as I clicked it. just like boolean, it changing from 0 to 1, but I have to click one more time to change it from 1 to 0. As in tutorial, he clicked the animation and return to 0 by itself (also, I would like to mention that the shape of the button is different, $$anonymous$$e is circle, the video is a block) but I already make sure that I'm using trigger, ins$$anonymous$$d of others.

8 Replies

· Add your reply
  • Sort: 
avatar image
8

Answer by georgeq · Jun 09, 2015 at 12:49 AM

This problem occurs when you set a trigger when a transition is still in progress. You code is generating a situation in which playerChop is triggered before the animation started by playerHit has ended... or playerHit is triggered for a second time before the transition started by the first trigger has ended. Use triggers only if you are sure the animation will play full, from begginig to end, before issuing another trigger... otherwise you will end up patching your code like this:

 animator.ResetTrigger("playerHit");
 animator.SetTrigger("playerChop");
 .
 .
 .
 animator.ResetTrigger("playerChop");
 animator.SetTrigger("playerHit");


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 bsoyluoglu · Dec 19, 2016 at 09:28 AM 0
Share

Thank you!!!

avatar image
4

Answer by memoid · Mar 12, 2017 at 05:51 PM

Yes I've come across this problem too (in Unity 5.5), and google is full of people asking about it! Like people say, the issue is that the Trigger stays on until a State transition needs that particular Trigger. E.g. if you are in State A and you Trigger a parameter which is for a transition from State B, it will stay on until we are in State B.

You can use Animator.ResetTrigger to clear the trigger. In small situations this is manageable, but in some situations I've found this to be a PITA.

E.g. I have a matrix of states with lots of transitions between them mapped to keyboard shortcuts. States A, B, C, D, E, F. And transitions A->B->C->D->E->F as well as A<->B, A<->C, A<->D, A<->E, A<->F etc. (Think of it as 'Next State', 'Go Home', and 'Jump to State').

Generally it works fine, but if I press a keyboard shortcut for a transition which is unavailable (e.g. the keyboard shortcut for A->D, while I'm in state C), then that Trigger stays on until I go to A, and then it immediately jumps back to D. Which is not what I want! To manually code in each of the ResetTriggers for each of the states etc would be a pain, so I've written the little function below to first clear ALL triggers, and then set the desired trigger.

 void AnimTrigger(string triggerName)
 {
     foreach(AnimatorControllerParameter p in animator.parameters)
         if (p.type == AnimatorControllerParameterType.Trigger)
             animator.ResetTrigger(p.name);
     animator.SetTrigger(triggerName);
 }


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 ZoraMikau · Jul 29, 2020 at 12:23 AM 0
Share

A more efficient way to do this would be to save all the trigger names after getting the animator (probably in Start), then to use those saved values instead of rechecking for them all again every time you call this function. Not sure if it matters with what whoever is reading this is doing, but figured it was worth mentioning! :)

avatar image
4

Answer by jezzaboy · Jan 25, 2019 at 09:18 AM

For those following the 2D roguelike training, clicking your "player" in the hierarchy will fix the issue and show the auto live link like in the video.

Comment
Add comment · Show 2 · 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 Siro360 · Apr 27, 2019 at 06:45 PM 0
Share

This worked for me! Reselect the thing you are animating in the scene view. This really looks like a bug to me.

avatar image adityaspt · Jul 27, 2020 at 12:16 PM 0
Share

Thanks man it worked. Just first selecting the character who has animator controller on him, then testing the triggers worked

avatar image
2

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 · Show 4 · 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 MichaelJT · May 25, 2017 at 02:12 PM 1
Share

I'm suffering the same issue and this didn't fix the issue.

avatar image obstinate · Aug 19, 2017 at 04:12 PM 0
Share

It works for me too. Thanks

avatar image FardinHaque · Mar 08, 2019 at 01:27 PM 0
Share

Thanks man! It worked!!

avatar image bitstrider · Jun 03, 2019 at 07:00 PM 0
Share

worked for me with 2018.3.14. seems like a bug since afaik "write default" affects the default value for properties of gameobjects being animated, not parameters like triggers https://forum.unity.com/threads/write-defaults-confusion-bug.392058/#post-2565600

avatar image
0

Answer by Bliko · Dec 01, 2017 at 10:20 PM

Had same problem as OP. I exited unity which prompted me to save, I did, and when I reopened the triggers were resetting, and also under the states I could see the bar filling up as the animation plays through, which I couldn't see before.

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.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Parameter does not exist 3 Answers

Animator Condition Not Working 0 Answers

Why is my character not flipping? 2 Answers

How to avoid double trigger behavior? 0 Answers

Animation Keypress Trigger Problem 0 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