title: Why is my animation jumping to the last keyframe when set in script?
body: <p>I am trying to rotate a gameObject by scripting it. This gameObject is a bone added in SkinningEditor, which should not make a difference. The script I wrote below is attached to the bone.</p>
  <pre><code>using System.Collections;
   using System.Collections.Generic;
   using UnityEngine;
   
   public class DeformBone : MonoBehaviour
   {
       void LateUpdate()
       {
           setAllCurves();
       }
   
   
       private void setAllCurves()
       {
           var angle = Quaternion.Euler(0, 0, 5);
   
           var rotXcurve = AnimationCurve.EaseInOut(0, 0, 5, angle.x);
           var rotYcurve = AnimationCurve.EaseInOut(0, 0, 5, angle.y);
           var rotZcurve = AnimationCurve.EaseInOut(0, 0, 5, angle.z);
           var rotWcurve = AnimationCurve.EaseInOut(0, 0, 5, angle.w);
   
           // set the curve here
           AnimationClip clip = new AnimationClip();
           clip.legacy = true;
   
           clip.SetCurve(&quot;&quot;, typeof(Transform), &quot;localRotation.x&quot;, rotXcurve);
           clip.SetCurve(&quot;&quot;, typeof(Transform), &quot;localRotation.y&quot;, rotYcurve);
           clip.SetCurve(&quot;&quot;, typeof(Transform), &quot;localRotation.z&quot;, rotZcurve);
           clip.SetCurve(&quot;&quot;, typeof(Transform), &quot;localRotation.w&quot;, rotWcurve);
   
           // play the curve here
           if (gameObject.GetComponent&lt;Animation&gt;() == null)
           {
               // add the component
               var animation = gameObject.AddComponent&lt;Animation&gt;();
               animation.playAutomatically = false;
               animation.wrapMode = WrapMode.PingPong;
               
           }
   
           GetComponent&lt;Animation&gt;().AddClip(clip, &quot;rotateyo&quot;);
           GetComponent&lt;Animation&gt;().Play(&quot;rotateyo&quot;);
       }
   }
  
  </code></pre>
  <p>However, the animation jitters quickly back and forth, jumping from keyframe to keyframe and then it gets faster and faster until it just looks a bit crazy. I want it to rotate at the angle indicated slowly. I have tried putting this in Start() - this only jumps it to the last keyframe where it stays, and FixedUpdate/Update where the same thing happens.</p>
  <p>I can see in the Inspector that I have successfully added an Animation to the bone and that the curves are being set up properly. What am I doing wrong?</p>