Search Unity

Animator bug: trigger does not disable automatically [Unity 5.6.0f2 (64-bit)]

Discussion in 'Animation' started by AkhmedAbasov, Apr 17, 2017.

  1. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    I need to play the animation once and I decided to use the triggers. You know that this works not as conceived?



    I'm forced to use the function ResetTrigger

    Code (csharp):
    1. if (stateInfo.IsName(FightSystem.FighterHName))
    2.                 animator.ResetTrigger(FightSystem.FighterHName);
    3.  
    Otherwise, the stage is played 2 times.
    What could be the problem? In my animation? Am I doing something wrong? Or this version of unity has such a feature?



    I hope I can be helped here, I do not want to program it all by hand.
     
  2. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Are you certain you're not setting the trigger multiple times?

    If no trigger was resetting properly, I'd imagine we'd have a lot more people screaming at us at the moment.
    If you can't figure it out, file a bug
     
  3. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    Yes, I am sure. In fact, the network has many similar questions. I think this is because of the transaction settings, but it is currently the default.
     
  4. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Please file a bug, we'll check it out
     
  5. AkhmedAbasov

    AkhmedAbasov

    Joined:
    Mar 13, 2014
    Posts:
    163
    Most likely I came across the problem described here. Just in case, I'll throw off a bug report.
    --
    Ultroman's answer is not 100% exact. The problem does not (always) occur when you trigger an animation that is currently being played. It does occur when you trigger an amination while a transition is still running.

    Let's say you have 2 animations: A and B and 2 triggers: tA and tB, animation A plays when tA gets triggered and animation B plays when tB gets triggered. If you trigger tA animation Awill start playing, but if you trigger tB before animation A has finished, tA won't be reset, it will remain true until animation A is played from begining to end. The same also happens if you trigger tA for a second time while animation A is still playing.

    So, if for some reason you need to trigger tB and you are not sure if animation A has finished, you should use ResetTrigger, I didn't understand why the guys at Unity decided to include this funtion until I stumbled upon this problem.

    To prevent this unwanted behaviour you should do something like this:

    1. animator.ResetTrigger("tA");
    2. animator.SetTigger("tB);
    --
     
    drew767 likes this.
  6. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Triggers stay triggered until a transition that uses them is taken.
    Whenever a transition using trigger tA is taken, the trigger gets reset when all layers have been evaluated (so that all layers have a chance to react to that trigger)
     
    Dave_Bowman likes this.
  7. Harald_Heide

    Harald_Heide

    Joined:
    Jul 22, 2015
    Posts:
    81
    Just experienced same problem with Version 2017.1.0f3 personal
    I use setTrigger from Update loop C#. Sometimes (Not Always) Trigger does not reset after triggered animation is played.
    I have with earlier releases done the exactly same thing with no problem. Also have some problem with debugging C sharp monobehaviours in vs 2017 from Unity 2017. I only have the Base Layer in my Animator controller
     
  8. sargo_unity

    sargo_unity

    Joined:
    Jan 26, 2020
    Posts:
    1
    I had same problem
    probably u are using Boolean instead of Trigger, u can see different shape next to it upload_2020-2-2_10-33-27.png
     
    thewall37 likes this.
  9. OrderOfOut

    OrderOfOut

    Joined:
    Sep 21, 2018
    Posts:
    37
    2019 has the same problem — I’ve put in breakpoints to assure I’m only setting the trigger once, but it never unsets on its own. The animation state that it triggers plays on an endless loop and the trigger stays set to true. (My player keeps getting hit endlessly, which would be funny if it weren’t frustrating)

    the documentation says that triggers set themselves to false right away, which is what’s confusing us because clearly there are conditions where it doesn’t.
     
  10. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Every trigger that was used to take a transition is reset right after the state machine is evaluated.
    If you have a reproducible case where it's not, please send us a bug report, because I have just reviewed the code, and I don't see any loopholes.

    Even just a description of what kind of transition is triggering multiple times would be useful to help diagnose.
     
  11. bmbzzx1

    bmbzzx1

    Joined:
    Jan 26, 2021
    Posts:
    2
    I have this issue but with mine, my character keeps triggering attack animation then locomation then back to attack! This only started happening when i put in a stopAttack trigger.
     
  12. Develax

    Develax

    Joined:
    Nov 14, 2017
    Posts:
    67
    Here is a reproduction of the "Normal" trigger getting stuck.

    Github project

    Unity version 2020.2.0f1

    In the first video it works as expected because I move the mouse slowly and OnPointerEnter/OnPointerExit events are fired in separate frames (first I move the pointer out of the box and then move it to the other one), thus _animator.SetTrigger() is called in separate frames as well.


    In the second video I move the mouse fast (from one box to another within one frame), so _animator.SetTrigger() is called twice in the same frame and because of that the "Normal" trigger gets stuck forever.
     
    Last edited: May 21, 2021
  13. jimmack

    jimmack

    Joined:
    May 2, 2016
    Posts:
    20
    I've just been struggling to work out why one of my triggers was being consumed, but the animation state wasn't changing. After several hours of trying all sorts of different things, I think I figured it out.

    I have two characters in the scene that have a default animation state. I use triggers to get them to their other animation state at different times. My trigger to get them back to their original state was called "Reset" in both animators. When setting this trigger on my second character, it was being consumed by the first character's animator. I renamed the trigger and now I'm getting the behaviour I expected.

    I don't recall seeing this documented or mentioned (please correct me if I'm wrong). If I'm right, could the documentation be updated to make this nice and clear :) Thanks.
     
  14. Unlabelled_Media

    Unlabelled_Media

    Joined:
    Sep 10, 2021
    Posts:
    2
    For those who did the same mistake I did, double check if there's not a transition in your looped clip. While doing the transitions between states it's possible to create an inner transition from clip to same clips by mistake which you can see by a small while triangle hanging under the clip. If that's the case just click on your clip and delete the inner transition and your trigger will reset automatically. Hope it helps someone
     
    DavidGeoffroy likes this.