Search Unity

[Mecanim 4.3] Animation event sent twice

Discussion in 'Animation' started by Philip.Roigard, Nov 28, 2013.

  1. Philip.Roigard

    Philip.Roigard

    Joined:
    Nov 28, 2013
    Posts:
    1
    Hi everyone, I have been searching all over for answers but have not been successful. I just install the new Unity 4.3 update and add 2 events to one of my animations I called them,

    EnableWeaponCollider
    DisableWeaponCollider

    now in my animator script I call these functions and debug log out when they are called. This is great however, both of these functions are being called twice every time. I don't want to have to do a Boolean check every time to see If it has been called already this is going to get very messy.

    How can I ensure that these events are only sent once, also could anyone who has successfully used this please explain briefly how the new event thing works and can I create an AnimationEvent in code anywhere?

    Thank you for reading :)
     
  2. NisseKisse

    NisseKisse

    Joined:
    Dec 27, 2012
    Posts:
    1
    Im experiencing a similar problem right now. An event in my mecanim animation seems to fire twice causing some unwanted effects. If i find a solution i'll try to remember to share it. (hopefully a more experienced developer than me can reply with a better solution soon).
     
  3. Maria Chernykh

    Maria Chernykh

    Joined:
    Oct 31, 2012
    Posts:
    7
    I've got the same problem. Anybody knows it's a bug or incorrect settings?
     
  4. Max12314

    Max12314

    Joined:
    Nov 28, 2013
    Posts:
    1
    I recently ran into this problem as well. Make sure you do not have two different states containing your animation clip with the event being fired. I am refering to the "Animator" editing window. Hope this helps!
     
  5. HowBoring

    HowBoring

    Joined:
    Aug 27, 2013
    Posts:
    7
  6. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,674
    There is a bug, event at time 0 are fire twice, there is a fix coming in teh next major release

    Sorry
    Best regards,
    Sonny
     
  7. FileThirteen

    FileThirteen

    Joined:
    Oct 23, 2012
    Posts:
    22
    I'm still getting this issue in 4.5.5f1. A function is getting double called from my animation. I am not sure if it has anything to do with it but I'm using a Blend Tree. I put a Debug.Log in my code to see what was happening and it is basically just double calling the function. Any work arounds to this? I've been trying to sync up a function using a timer to match up with the frame of the animation but it's getting pretty convoluted.
     
  8. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,674
    Unfortunatelly no there is no workaround, we did try to backport the fix from 5.0 to 4.5 but it was too risky.

    So the bug is that event at time 0 are fire twice, all other event should be fire only once.
     
  9. windness

    windness

    Joined:
    Oct 27, 2014
    Posts:
    3
    I also found this buf in 4.5.5f1. It will occur almost every time when the event time is 0, and when the event time is close to 0, it will occur too but the frenquency is much lower.
     
  10. MayankBhaisora

    MayankBhaisora

    Joined:
    Nov 23, 2015
    Posts:
    1
    An animation is being played twice while using setTrigger. But is being played once while triggering by clicking on trigger radio button in animator window. One time run is expected. I am using unity 5.3.
    Can anyone help me?
    Thank you.
     
  11. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,674
    @anonymousMac, we often seen this problem when user use Input.GetButton to set there trigger. GetButton will return true as long as the key is pressed, so if while you press the key down you get two update of the engine, The first update willl set the trigger to true, then the animator get evaluated, consume the trigger(reset back to false) and start the transition, then you get the second Update but you still have the key pressed so you script set the trigger to true.

    In this case you should use GetButtonDown which return true only on the frame that the key was pressed.
     
    nighthawkcy likes this.
  12. tjscott

    tjscott

    Joined:
    Sep 22, 2014
    Posts:
    12
    I'm getting this bug even when the Event is not at time 0. My event is at about time .23 and the event is fired twice. It is not only fired twice, but the second time it is fired is not concurrent. So, what happens is that the event fires at the correct time, but then when the entire animation has completed, the event is fired again. This is a delay of almost a full second. There are no blend trees in my Animator and the only thing that happens after this animation is played is that it transitions to the idle animation. I verified that the code that is being fired from the event is only called via this animation/event. If I remove the event, the function it was calling is no longer called at all. So, somehow, this event at .23 seconds gets called at the end of the animation cycle for no apparent reason.

    EDIT: My Unity version is 5.3.1p2

    EDIT: I figured out my issue. The attack animation that had the event on it was set to loop. So, even though it had a transition to idle, it would begin to play the attack animation again before transitioning. This caused the event to fire again.
     
    Last edited: Feb 4, 2016
    justtime likes this.
  13. Taphos

    Taphos

    Joined:
    Dec 5, 2012
    Posts:
    11
    Same problem when playing an animation clip using Playable API, all events are called twice. Unity 5.5.0p1
     
  14. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,674
    Please log a bug with repro step, we cannot do anything with just a sentence on the forum.
    We do have runtime test that cover this functionnality every day and there are all green so you are probably triggering a corner case that we are not aware of.
     
  15. Delernaville

    Delernaville

    Joined:
    Jun 4, 2017
    Posts:
    2
    Hi, I was learning to use Unity a many years ago but left it and got into movie making software with iClone. I have gotten back into using Unity again about a month ago.

    I am doing character animations from Idle as trigger and made it able to call jump as bool or running as bool. Also made jump callable from running also when it gets called. From both idle or running if I set the call to jump with 'Has Exit Time' ticked then the jump wouldn't run until the animation that called it got to its end but the jump would run correctly only once and then go back to the animation that called it. Then I set the 'Has Exit Time' unticked to let jump run as soon as it got called. Problem was that the jump would then run twice every time and I couldn't find why it was doing that.

    However I did find a way to stop it in the script and it now only runs once every time I press the button in my axis.
    I load the axis button value into a variable.
    if the variable=0 and the button was pressed then the variable gets set to 1.
    if variable =1 then the jump animation gets set to run and the variable then gets set to -20
    then each time void Update() gets called and if the variable is less then 0 then the varable gets 1 added to it.
    That repeats until the variable gets back to 0 and when only when it gets back to 0 is when the jump animation can get called again. That fixed it for me, the jump only ever happens once now each time I press the button.

    By the way, posted this because I was looking for an answer and I found this. Decided to post what I did. Certainly might be a better way to do it but I haven't found it yet and this works well....so?

    Here is the code I made so far. More to do yet when I start making a proper game, Im just re-learning at the moment.
     
  16. Delernaville

    Delernaville

    Joined:
    Jun 4, 2017
    Posts:
    2
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class GrannyAnimationScript : MonoBehaviour
    {
    public float runSpeed = 0.1F;
    public float rotationSpeed = 10F;
    public float LeftVerticalValue = 0;
    public float RotateValue = 0;
    public float YButtonValue = 0;
    float ybutton=0;
    static Animator anim;
    // Start is called before the first frame update
    void Start()
    {
    anim = GetComponent<Animator>();
    anim.SetBool("isIdle",true);
    runSpeed = 0.1F;
    }
    // Update is called once per frame
    void Update()
    {
    float walk = Input.GetAxis("LeftVertical") * runSpeed;
    float rotate = Input.GetAxis("RightVertical") * rotationSpeed;
    if(rotate != 0)
    {
    if(rotate < 0){rotate=-2;}else{rotate=2;}
    }
    LeftVerticalValue=walk;
    RotateValue=rotate;
    transform.Translate(0,0,walk);
    transform.Rotate(0,rotate,0);

    if(ybutton != 0)
    { ybutton=ybutton+1;
    }else{
    ybutton = Input.GetAxis("YButton");
    }

    YButtonValue = ybutton;
    if(ybutton==1)
    { anim.SetTrigger("isJumping");
    ybutton=-20;
    }
    if(walk != 0)
    { anim.SetBool("isRunning",true);
    anim.SetBool("isIdle",false);
    }else{
    anim.SetBool("isRunning",false);
    anim.SetBool("isIdle",true);
    }
    }
    }
     
unityunity