Search Unity

Trying to trigger State from button, failing (triggers act weird)

Discussion in 'Animation' started by kikendo, Sep 22, 2017.

  1. kikendo

    kikendo

    Joined:
    Jul 19, 2017
    Posts:
    61
    Hi guys,

    My problem today is a bit weird, as I don't really understand what is going on.

    I have a Camera with 3 states of animation, and 2 triggers that change between them. Here are the three states:



    The triggers are called "goOptions" and "goGame"

    When I click on the triggers while running the game, it works fine, it goes from one state to the other
    Now the problem is when I assign this action to UI buttons. I set buttons to set the triggers like this:



    However what usually happens is that the animator goes from one state to the next and then bounces back on its own. I notice that the triggers get "stuck" sometimes on the opposite end, which I think triggers the bouncing back after I click on an option.

    Why are the triggers getting stuck? I thought they cleared on their own after the animation transitioned?

    I was doing this with code before (instead of the button calling an Animator>SetTrigger function, calling a script that did that instead) and the result was the same.

    Any help greatly appreciated.
     
  2. kikendo

    kikendo

    Joined:
    Jul 19, 2017
    Posts:
    61
    I still haven't been able to figure out why this isn't working. Any help?
     
  3. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,536
    If you trigger an event it will greenlight until it is consumed, you may be firing the button to go back to the menu before firing the one that starts the chain which leads to it flying through the entire chain since all of the triggers are primed.

    Can't really see what event goes where, so there's no way to tell.
     
  4. kikendo

    kikendo

    Joined:
    Jul 19, 2017
    Posts:
    61
    Sorry, maybe I should have explained more the transition.

    When I click a button on the scene, the firsttrigger (goOptions) is activated and "Options" state plays. It doesn't loop, so when it ends, It stays there, and this is in 3D space a different area (the transition is camera movements) where another button resides, that triggers the second transition to "options-to-camera" which is a reverse animation of the previous anim. There is no way I could be clicking the main button again, unless something I laid out is wrong.

    Now I am looking at the Trigger window on the Animator, and what I see happens is that the event isn't being "consumed" after a transition happens. So when I click the next one, there's TWO activated triggers, and this causes the back and forth. But why is it not being unset after the transition happens?

    Here is a short video showing what it's doing when I am clicking on the buttons, one after the other:
    2017-09-25 15-20-28.mp4
     
  5. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    this is usually caused by someone calling settrigger twice in consecutive frame, trigger are reset when the transition start so if in the frame after you call settrigger again it won't be consumed.

    Try to play the game paused from the editor with the animator window open and live link ON and click on next frame to see what is going on.
     
  6. kikendo

    kikendo

    Joined:
    Jul 19, 2017
    Posts:
    61
    OK, I can try that, although I wouldn't be sure who is doing this!
    However I do not know what you mean with "live link", I can tell that if I run this in pause mode, I cannot click the buttons, so you might mean some option that will allow me to do so. Can you explain that to me? I googled and found no answer.

    Just to be clear, this happens only when I click the buttons, not when I click the triggers on the Animator interface.
     
  7. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    live link refer to the animator windows showing debug info while in play mode, like the progression of each state, parameter's value, etc ...

    right UI can be tricky in pause mode, in this case you will need some kind of proxy function for SetTrigger that will allow you to trap the call site
    so rather than setting Animator.SetTrigger in you're OnClick event call you're proxy function which should call Animator.SetTrigger, then set a break point in you're proxy function and debug.
     
  8. kikendo

    kikendo

    Joined:
    Jul 19, 2017
    Posts:
    61
    I still can't get this scene to make triggers work properly. Any help appreciated :(