Search Unity

Reset All AnimationTriggers?

Discussion in 'Animation' started by camerontownsend, Oct 11, 2020.

  1. camerontownsend

    camerontownsend

    Joined:
    Mar 7, 2019
    Posts:
    14
    Hello all!

    I understand that a simple ResetTrigger can be used to basically stop playing a current animation by calling it out specifically - for ex. I'm pretty sure something like GetComponent<Animator>().ResetTrigger("JogTrigger"); could theoretically stop a jog animation from playing.

    However, I have a whole lot of animations that can flow into each other, and I definitely don't want to have to put a wall of reset triggers in my script. Is there a such thing as a "ResetAllTriggers" or something like that? Am I being too vague? I'm still very new to Unity.

    Thank you all in advance!
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    ResetTrigger just resets a trigger that you previously set with SetTrigger. It doesn't stop playing the current animation.

    Animator.parameters gives you access to all the parameters so you could implement a ResetAllTriggers method.
     
  3. JonX7

    JonX7

    Joined:
    Jul 4, 2016
    Posts:
    4
    Yeah, you'll have to implement it yourself, like this:

    private void ResetAllTriggers()
    {
    foreach (var param in Animator.parameters)
    {
    if (param.type == AnimatorControllerParameterType.Trigger)
    {
    Animator.ResetTrigger(param.name);
    }
    }
    }
     
  4. Deleted User

    Deleted User

    Guest

    You can implement it as extension method

    public static void ResetAllAnimatorTriggers(this Animator animator)
    {
    foreach (var trigger in animator.parameters)
    {
    if (trigger.type == AnimatorControllerParameterType.Trigger)
    {
    animator.ResetTrigger(trigger.name);
    }
    }
    }
     
  5. paul-masri-stone

    paul-masri-stone

    Joined:
    Mar 23, 2020
    Posts:
    49
    What does it mean to 'reset a trigger'?

    According to Unity docs for `SetTrigger()`, "Triggers have a true option which automatically returns back to false". My understanding has been that when I use `SetTrigger()`, unlike a `bool` it will immediately reset ready for reuse. I'm obviously missing something.
     
  6. GodlikeAurora

    GodlikeAurora

    Joined:
    Dec 7, 2016
    Posts:
    14
    Trigger will still active until its transition ended. So if you're calling several triggers, it will be "queued". This is why you need a ResetTrigger() method.
     
  7. vandale_

    vandale_

    Joined:
    Aug 16, 2019
    Posts:
    3
    thank you for this! :)