Search Unity

Animation Transition from AnyState issue

Discussion in 'Animation' started by fangye_Studio, Dec 8, 2019.

  1. fangye_Studio

    fangye_Studio

    Joined:
    Nov 19, 2012
    Posts:
    26
    I have animator state map for NPC,from Anystate to Hit and Death

    upload_2019-12-8_11-9-20.png

    On AnyState, there are 3 transitions anystate to death / to hit / to Jump Start .
    upload_2019-12-8_11-9-25.png

    the transition setting on death and Hit
    upload_2019-12-8_11-9-32.png
    from anystate to hit
    upload_2019-12-8_11-19-38.png


    and the transition from hit to locomotion idle , using Exit time
    upload_2019-12-8_11-11-53.png


    my willing is that to make NPC keep playing hit when the hit triggered by the player, after the dying event triggered, it should abort to play death anim immediately.

    the funny thing now is that the hit trigger animation looks like queued but not canceled when the dying is triggered, after the NPC plays into dying animation, in the hit to dying half transition, it goes back to the hit animation, then goes to locomotion as idle, which is totally not expected.


    I have set both transitions to Current and Ordered interruption , and make the anystate to death
     
    Last edited: Dec 8, 2019
  2. fangye_Studio

    fangye_Studio

    Joined:
    Nov 19, 2012
    Posts:
    26
    I attached a statemachine behaviour script to debug out the state name OnStateEnter and OnStateExit
    and wrote a debug script press every 5 times to trigger a die event ,
    upload_2019-12-8_11-29-0.png

    as you can see, after the dying event triggered, it should trigger and play the dying animation only, but the previously None finished hit animation still comes back and interrupt the dying animation.
    upload_2019-12-8_11-26-13.png

    needs you guys help on this . thanks a lot ~
     
  3. fangye_Studio

    fangye_Studio

    Joined:
    Nov 19, 2012
    Posts:
    26
    by now I use Animator.ResetTrigger("hit") before trigger death anim to solve this first, if anyone has better ideas please reply me, thanks
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    It sounds like you've found the solution: reset your trggers and stop setting them once you know the character is dead. If you use triggers you will pretty much always want to reset all the others whenever you set one of them. Otherwise they will remain set until they get used so if you press jump while attacking repeatedly, it will either finish all your attacks before jumping or jump and then attack again when you land. Either of those would feel unresponsive for the player because you could be responding to inputs they made several seconds ago.

    You might be interested in trying out Animancer (link in my signature) which lets you play whatever animations you want on demand instead of fiddling around with Animator Controllers, triggers, etc.
     
  5. fangye_Studio

    fangye_Studio

    Joined:
    Nov 19, 2012
    Posts:
    26
    hi, Kybernetik
    thanks for the reply, I will look into your asset definitely. for this reset trigger thing, Can I always reset it before trigger a new one event on the same trigger animation? like below:


    //once press fire
    aniamtor.ResetTrigger("hit");
    aniamtor.Trigger("hit");
     
  6. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    You can, but that's pointless. A trigger is just a bool that will set itself to false when a transition uses it, so all you're doing there is setting it to false then immediately back to true which won't achieve anything different from just calling animator.SetTrigger.

    What I meant is that when you SetTrigger("hit"), you will want to ResetTrigger all of your other triggers such as attack, jump, etc. (obviously I don't actually know what's in your game). And when you SetTrigger("dying") you will want to ResetTrigger("hit") and all those others as well.
     
  7. fangye_Studio

    fangye_Studio

    Joined:
    Nov 19, 2012
    Posts:
    26
    ok ok, understand, thanks a lot !
     
  8. cotevelino

    cotevelino

    Joined:
    Jul 3, 2020
    Posts:
    5
    Necropost from a long time ago but google still brought me here lol.
    One thing that helped me with this problem was un-checking the "Can transition to self" box in animation transition inspector.
     

    Attached Files:

    Kenan_Nynor and CorWilson like this.
  9. Deathcupcake12

    Deathcupcake12

    Joined:
    Jan 15, 2024
    Posts:
    1
    Thank you for this! Very new to Unity but this helped me a ton. :)