Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Bug or intended implementation (Animator.Play())?

Discussion in 'Animation' started by BabouDev, Nov 4, 2018.

  1. BabouDev

    BabouDev

    Joined:
    Feb 3, 2015
    Posts:
    13
    Hello,

    I am new to Unity development. During my update phase, I settle the state of my character and play a particular clip, During LateUpdate, I then process the state after the animator as updated.

    There happens to be undefined behavior when I have multiple calls to Animator.Play() in the same frame (or before Animation system is updated). My assumption was that the last call to it will be the clip to be played but that's not the case and it cause some weird really hard to debug situations.

    For example,


    Code (CSharp):
    1.  if (Input.GetMouseButtonDown(1))
    2. {
    3. myAnimator.Play("idle");
    4. myAnimator.Play("attack");
    5. }
    When I click, The animation that is played is "toggled" between the two. It is never consistently attack. I tried to find the unity source code but the function is externed.

    Code (CSharp):
    1. [FreeFunction(Name = "AnimatorBindings::Play", HasExplicitThis = true)]
    2.         extern public void Play(int stateNameHash, [DefaultValue("-1")] int layer, [DefaultValue("float.NegativeInfinity")] float normalizedTime);
    Any help would be appreciated. Thanks.
     
  2. SilentSin

    SilentSin

    Joined:
    Jan 3, 2013
    Posts:
    273
    That sounds like a bug so you should submit a bug report.

    In the meantime, I can confirm that my Animancer plugin would not have that problem. Or you could just hack it to only call Play once at the end of your function.