Search Unity

Animation event not triggering

Discussion in 'Animation' started by Happy_Jingle, Feb 13, 2017.

  1. Happy_Jingle

    Happy_Jingle

    Joined:
    Mar 9, 2014
    Posts:
    102
    Currently in my game a lot of events are triggered from within an animation and occasionally they seem to be skipped over. It's imperative that an event never get skipped, how do I make sure this doesn't happen?
    Here are the settings on all my animations:
    Example of how events are placed:
     
    MamaCatDev likes this.
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,779
  3. Happy_Jingle

    Happy_Jingle

    Joined:
    Mar 9, 2014
    Posts:
    102
    The answers on a lot of the threads I've gone through are quite old, I was hoping there was updated information. Furthermore they aren't actually "answers" more like "this is broken don't use it" so I was hoping to find an actual answer.
     
  4. omegabytestudio

    omegabytestudio

    Joined:
    Nov 9, 2015
    Posts:
    77
    @Happy_Jingle

    I feel you man.

    I might be able to help you, not sure if it's the same issue.

    I had trouble when I tried to call an event on a frame, and that frame was occuring during a transition to another animation.

    Like If I was punching, and mid animation I would kick, the last frame wouldn't call the event.

    Could it be your issue too?

    To resolve this issue, I'm using a way that might not be the best, but it works for me.

    I have both event on the animator and state machine behavior with the same event call on the OnStateExit fonction.

    Why both?

    Event : Sometime won't call on transition.

    State Machine Behavior : Won't call OnStateExit if the animation loop, and it was looping for me. If you aren't looping, you can only use State Machine Behavior.

    I hope it helps you!
     
    vladutstefan27 and b453M3NtCL0WN like this.
  5. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,634
    Please log a bug if there is something that doesn't work as expected.
    We do have over 50 different test for animation events that are run everytime we do build unity that cover many edge case.

    If there is some case that still doesn't work we would like to know
     
    OfficialHermie likes this.
  6. omegabytestudio

    omegabytestudio

    Joined:
    Nov 9, 2015
    Posts:
    77
    Does the situation I describe is a bug? I just thought it was how it was supose to work?
     
  7. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,634
    If you expect that your animation events should be fired but it not fired then yes log a bug, we will do the investigation and if we found out that it broken we gonna fix it, if it not broken we will give you an explanation why we think it work as expected.

    So yes log a bug
     
    OfficialHermie and theANMATOR2b like this.
  8. Ylisar

    Ylisar

    Joined:
    Jan 27, 2014
    Posts:
    10
    Where is the documentation for animation events with mecanim? I can only seem to find the docs for animation events when using the legacy system. For example, how does events work during a transition? Some googling seems to suggest they're broken with mecanim, but those are mostly old posts.
     
    Deeeds likes this.
  9. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,634
    There is nothing specific to mecanim or legacy, basically if a clip is currently playing it should trigger events.

    A transition is essentially a cross fade between 2 animation clip, so as long as both clip are played they should both trigger animation events.

    There is no know issue with animation events at the moment in 2017.1 and on newer version so I would expect them to work reliably
     
    Ylisar likes this.
  10. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    374
    Last frames on animations are definently skipped at times. Especially during a transition to another anim. Giving me headaches
     
    themeshpotato and Deeeds like this.
  11. Mijail_Bitboys

    Mijail_Bitboys

    Joined:
    Apr 22, 2015
    Posts:
    146
    Any news about how to solve this?
    For me it is impossible to use animation events because sometimes they work and sometimes they do not.
    I just want to send a message to another script when the animation reaches a certain frame but it does not work exactly. It's a simple trigger animation.
     
    Deeeds likes this.
  12. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,634
    Please log a bug, there is currently no know issue about animation events not firing for the animator component
     
  13. ed7k

    ed7k

    Joined:
    Jul 4, 2016
    Posts:
    1
    Deeeds and theANMATOR2b like this.
  14. SergioMartinPulido

    SergioMartinPulido

    Joined:
    Mar 19, 2018
    Posts:
    1
    Hello I am having the same problem. I will introduce my case:
    I am using Animation Events to trigger sounds at a specific frame. For some reasons the events placed at the first key frame are only triggered the first time I play the animation. The next times I try to play the animation the Animation Event is skipped. I am using Simple Animation Component to trigger the animations not Mecanim. (So we are not using transition blending or exit time)

    https://blogs.unity3d.com/es/2017/11/28/introducing-the-simple-animation-component/

    In theory uses Playables to play the animations.
    My unity version is 2017.3.1f1

    Any help will be very usefull

    Regards

    trunk (Ejecución) - Microsoft Visual Studio .jpg
    PrtScr capture_3.jpg

    Animation event not triggering  Unity Community - Google Chrome.jpg
     
    Deeeds likes this.
  15. willianbrasil

    willianbrasil

    Joined:
    Oct 17, 2017
    Posts:
    5
    Hi i've worked on three different projects with Unity and i've always had problems with animation events at the end of animation because they seem to fire whenever they want to, to solve this i've come up with two methods:

    1: Put a phantom frame at the end of the animation, after the event frame, and example of phantom frame is a GameObject property which will be enabled/disabled according to your current animation so it won't change anything.

    2: Get the animation length which you desire to activate the event and at the end of the desired animation activate the event.

    Obs: I've never used state machine behaviours, so it might be a good alternative.
     
  16. NathanJSmith

    NathanJSmith

    Joined:
    May 11, 2018
    Posts:
    49
    If Blend Animation causes Animation Event unreliable, then I have to drop Animation Event method. I can use StateMachineBehaviour & Animator.GetCurrentAnimatorStateInfo.normalizedTime to handle the event myself for this case (cause I can't drop Blend Animation for this case)
     
  17. coute

    coute

    Joined:
    Jul 26, 2014
    Posts:
    6
    I'm having this problem as well. I'm using Animation Events to tell my Behavior Designer tree when an animation has finished playing (the animation event fires on the last frame of the animation). In the tree, it just waits forever until it gets the message that the animation has finished. It works most of the time, but sometimes I would find an enemy who is in the next crossfaded animation state but whose behavior tree is still waiting for the animation end event-fired message for the previous animation.

    Nathan's workaround sounds like a right pain in the ass. I have a lot of events besides the end of animation event so any news on a permanent fix for this would be appreciated.

    EDIT: Just to be clear, the animations I'm putting the animation end event on are not looping. I've tried other solutions for telling when an animation has ended but those had problems as well.
     
    Last edited: Nov 18, 2018
  18. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    434
    It's been a while since I had to use Mecanim, but could it be that the transition is starting before the end of the animation and timed to finish at the end of the animation? In that case, floating point error between the keyframe/event and the system that determines which states are playing could be causing the state to stop before it actually evaluates the last frame. That would explain why it only happens some of the time since it would be precision errors accumulated from the varying delta time.
     
  19. RLord321

    RLord321

    Joined:
    Feb 25, 2017
    Posts:
    2
    I had the same issue...but I fixed it. I had an trigger at the end of the animation frame and it was firing based on debugging but my code was not handing my characters different action properly. For example, I had the trigger call a function when the animation ended to indicate the attack was done so the AI could do something else...like attack again. To make a long story short, I believe it may have been continuing an animation before it actually stopped and maybe starting again? Not sure but when I started the animation specifically starting at frame 0, it works fine:

    anim.Play( "attack", -1, 0);

    I hope this helps!
     
  20. tataygames

    tataygames

    Joined:
    Aug 4, 2016
    Posts:
    20
    Tried it on unity 5.5.6 and the last frame with trigger event is still skipping.


     
  21. coute

    coute

    Joined:
    Jul 26, 2014
    Posts:
    6
    I'm using CrossFade so that's not going to work. I still have this issue and it's really annoying.

     
  22. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    448
    @Mecanim-Dev I have filed a bug report (Case 1113342) in December that deals with the same issue.
    I struggled a bit to create a project / sample scene that would make it most easy for the one who handles this report to follow / see the bug.
    Unfortunately I filed a difficult-to-follow bug report (Case 1113170) before that.
    In Case 1113342 I explained that this new case is an improved bug report of Case 1113170 and that Case 1113170 can be closed.
    Case 1113342 is still open, and Case 1113170 is closed.
    This is perfectly fine, but I wonder what the status of Case 1113342 is since it appears open and not "under investigation" or so. I'm afraid this case is somehow forgotten due to my "double posting".
    Do you think you could perhaps check if Case 1113342 is still under investigation?
    Thank you very much!
    (Sorry for the difficult explanation!)
     
  23. seldron333

    seldron333

    Joined:
    Mar 9, 2019
    Posts:
    3
    I had the same problem, and I realised that my layers had 0 weight.(if that helps)