Search Unity

Mecanim bool not persisting through animations?

Discussion in 'Animation' started by Simon-R, Jan 24, 2020.

  1. Simon-R

    Simon-R

    Joined:
    Mar 29, 2014
    Posts:
    11
    Evening folks,

    I'm considering a change to how I handle melee combat animations in my project. I'd like to explore having attacks change based on how long a button is held. I had planned on using a series of bools to controls this, with the duration of the bool being held moving through a series of animations with different resultant actions, but I'm finding that bool params are being consumed at the first transition in the animator.

    I can't imagine I'm the first person to try this approach, and I'm probably missing something super basic. If anyone has a good thread to follow or suggestions, I'd very much appreciate it - I haven't been able to find anything pertinent.

    Thank you!
     
  2. Inxentas

    Inxentas

    Joined:
    Jan 15, 2020
    Posts:
    278
    My best guess is that you're trying to express the concept of time to an Animation Controller using an unsuitable format (bool). Why not have the code dictate what attack animation is going to play based on time by incressing an int over time, and then pass all controllers that int when it is released?
     
  3. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Bool parameters only change when you change them.

    Trigger parameters are like bools, but get reset once they trigger something. But beware that this means they won't be reset if they don't trigger anything, so if for example you are attacking and you set triggers to both attack again and jump, only one of those will get used and the other one will still be set until after that action when it will then immediately trigger the other action which might be several seconds old by that point so you are responding to old inputs that the player might not care about anymore which makes the controls seem very clunky. So when using triggers it is usually best to reset every other trigger whenever you set a new one, which obviously makes the implementation very tedious.

    Instead, you can just call animator.Play("State Name") (or CrossFade) so that you don't need to set up parameters or transitions in the first place. You still need to make the states so it's not the most streamlined approach, but that's how I always did it when I still used Animator Controllers.

    Or you might be interested in Animancer (link in my signature) which lets you use a purely code based approach. Want to play an animation clip? Just call animancer.Play(clip) without needing to set up any states or anything else beforehand.