Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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

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

  1. rootbeerdev


    Feb 3, 2015

    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


    Jan 3, 2013
    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.