Code generated animation clip missing component when assigned to an animation controller.

I am using animation clips/curves to record positional data from a vive tracker during run-time. After generating the clip and saving it as an asset I am unable to drop it into an animation controller without getting a “Missing Component” error.

Screenshot of the error

Initially I suspected the issue was with the relative path chosen. I cleared the path and the issue persisted. When I select the property in the animation it highlights the correct corresponding gameobject in the hierarchy. When I review the original clip before attaching it to an animation controller the positional data is present and updates as expected. After dropping it into the animation controller all of the property values zero out but all the frames are still present.

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class MovementRecording : MonoBehaviour
    public List<Keyframe> ksx = new List<Keyframe>();
    public List<Keyframe> ksy = new List<Keyframe>();
    public List<Keyframe> ksz = new List<Keyframe>();

    public Transform leftHand; 

    private float _timeStart = 0.0f;
    private float _timePassed = 0.0f;

    private bool _started = false;
    private void Update()
        if (Input.GetKeyDown(KeyCode.Space))
            if (!_started)
                _started = true;
                InvokeRepeating("Record", 0.0f, 0.1f);
            }else if (_started)
                _started = false;

    private void Record()
        ksx.Add(new Keyframe((ksx.Count + 1) * 0.1f, leftHand.position.x));
        ksy.Add(new Keyframe((ksy.Count + 1) * 0.1f, leftHand.position.y));
        ksz.Add(new Keyframe((ksz.Count + 1) * 0.1f, leftHand.position.z));

    private void FinishRecord()
        AnimationClip clip = new AnimationClip();
        AnimationCurve curve = new AnimationCurve(ksx.ToArray());
        clip.SetCurve("", typeof(Transform), "position.x", curve);
        curve = new AnimationCurve(ksy.ToArray());
        clip.SetCurve("", typeof(Transform), "position.y", curve);
        curve = new AnimationCurve(ksz.ToArray());
        clip.SetCurve("", typeof(Transform), "position.z", curve);

        AssetDatabase.CreateAsset(clip, "Assets/Test.anim");


Any help would be really appreciated! :slight_smile:


I was using the wrong property name for the curve. It’s not position.x it’s localPosition.x.