Search Unity

Resolved animator.Update(0) introduces stutter

Discussion in 'Animation' started by bobadi, Feb 17, 2023.

  1. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    672
    used the example codes for this animation update(0) to resume anim.Play
    it works but it is not smooth

    update: tested this is 2022.2 and looks like it is not present

    timescale 1, 0.5, 0.1
    animupdate0.gif

    also tried resetting rootposition and bodyposition

    code
    Code (CSharp):
    1. public class testAUpdate : MonoBehaviour {
    2.  
    3.     public Transform root;
    4.     public Transform bone;
    5.     public Vector3 position;
    6.     public Vector3 offset;
    7.  
    8.     public float NT;
    9.     public string anim;
    10.     public float testT = 0.25f;
    11.     public Animator animator;
    12.     float startT;
    13.     bool started;
    14.  
    15.     AnimatorStateInfo[] layerInfo;
    16.  
    17.     void Update () {
    18.  
    19.         if (Input.GetKeyDown (KeyCode.Space)) {
    20.  
    21.             startT = Time.time;
    22.             started = true;
    23.             offset = Vector3.zero;
    24.             animator.CrossFadeInFixedTime (anim, 0.2f);
    25.  
    26.         }
    27.  
    28.         if (started) {
    29.  
    30.             if (Time.time - startT > testT && offset == Vector3.zero) {
    31.  
    32.                 layerInfo = new AnimatorStateInfo[animator.layerCount];
    33.                 for (int i = 0; i < animator.layerCount; i++)
    34.                 {
    35.                     layerInfo[i] = animator.GetCurrentAnimatorStateInfo(i);
    36.                 }
    37.                  
    38.                 animator.Play (anim, 0, NT);
    39.                 animator.Update(0);
    40.  
    41.                 offset = bone.position - root.position;
    42.                 position = bone.position;
    43.  
    44.                 // Push back state
    45.                 for (int i = 0; i < animator.layerCount; i++)
    46.                 {
    47.                     animator.Play(anim, i, layerInfo[i].normalizedTime);
    48.                 }
    49.             }
    50.         }
    51.  
    52.     }
    53. }
     
    Last edited: Feb 17, 2023
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Report a bug via the Help menu. There likely isn't anything you can do about this issue if you keep using Animator Controllers.
     
    DevDunk likes this.
  3. bobadi

    bobadi

    Joined:
    Jan 3, 2019
    Posts:
    672
  4. SF_FrankvHoof

    SF_FrankvHoof

    Joined:
    Apr 1, 2022
    Posts:
    780
    That's.. ehm... Quite a time-frame you have there..