Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Discussion Simple tracking of animation status, for guarding player input

Discussion in 'Animation' started by BenjaminApprill, Jan 8, 2024.

  1. BenjaminApprill

    BenjaminApprill

    Joined:
    Aug 1, 2022
    Posts:
    132
    Hello. I'm sure this has been discussed before in some capacity, so I will simply start with the example I've got.

    I have Left-Click on the Mouse set to start an Animation. That part is working correctly, except for one thing. During the animation, clicking the mouse again will trip the trigger on the Animator. The idea is for the click to not register until after the Animation is complete.

    I am aware of attaching an Animation Event to the Animation. However, this requires an arbitrary boolean somewhere to track this status. If I use a Parameter for this, it can be added as a Transition Condition. However, I am worried this will produce a lot of overhead for simply tracking animation status. Especially if this turns into a routine kind of thing to track...

    Are there any obvious approaches I am missing? I am curious about what will operate the best, or if this is approach is the only way to do it without using a Script on the GameObject. I know I can just write a script and track the state, but I am curious about solutions that leverage the Engine as much as possible.
     
  2. BenjaminApprill

    BenjaminApprill

    Joined:
    Aug 1, 2022
    Posts:
    132
    ok, I figured this out.

    It is doable with a Trigger parameter. You set it up by making the incoming Transition conditional on the trigger. You then also make the exiting Transition conditional on the SAME trigger. You have to then un-check the "Has Exit Time" option on BOTH Transitions...

    Since you are using the Trigger parameter, the Trigger state resets itself at the end of the clip. This triggers the exit transition automatically, if "Has Exit Time" is de-activated. The Trigger state is essentially determining the exit time, which is one loop of the clip.

    This is actually quite elegant. It is essentially the same thing as tracking the state of the clip transition with a bool, using an Event to toggle the bool at the end of the clip, and requiring a further guard bool to not trigger the boolean again until the clip has completed... And this also requires a script to achieve a lot of this...

    Instead, it can simply be replaced by using one Trigger parameter, and the correct Transition settings.