Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why are Animated Clip data always returning null curve and clip definitions? 2017.3.1f1

Discussion in 'Timeline' started by fatblueduck, Apr 18, 2018.

  1. fatblueduck

    fatblueduck

    Joined:
    Feb 27, 2018
    Posts:
    5
    Hello,

    I'm hoping to probe Unity animation keyframe data using C#. I've tried accessing keyframes from TimelineClip and AnimationClip data at my scene, but the 'curve' and 'clip' data on these objects always appear null/empty.

    I'm not expecting null data, because curve and keyframe data are added to the scene and they are visible in the Unity GUI Timeline and Curve editing windows.

    To add the curves I created a new Timeline/Director and used the 'record' button to change the mesh positions at points on the timeline. When recording was stopped, I right-click converted the track to "Animation Clip".

    What I'm doing wrong? How can I access keyframe data? Why are curve data on my TimelineClip instances null?

    The function I'm using to Log the Timeline data

    Code (CSharp):
    1.  
    2.     public static void accessTimeline ()
    3.     {
    4.         UnityEngine.SceneManagement.Scene scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
    5.         IList<GameObject> sceneObjects = scene.GetRootGameObjects();
    6.         string logstr = "timeline, ";
    7.  
    8.         logstr += "\n scene: " + scene.name + " type: " + scene.GetType().Name;
    9.         foreach (GameObject g in sceneObjects)
    10.         {
    11.             PlayableDirector director = g.GetComponent<PlayableDirector>();
    12.             logstr += "\n      * object: " + g.name + " type: " + g.GetType().Name + " isdirectory?:" + (director != null);
    13.             if (director != null)
    14.             {
    15.                 TimelineAsset timelineAsset = director.playableAsset as TimelineAsset;
    16.                 if (timelineAsset == null)
    17.                     continue;
    18.  
    19.                 IEnumerable<UnityEngine.Timeline.TrackAsset> tracks = timelineAsset.GetOutputTracks();
    20.                 logstr += "\n            timelineAsset: " + timelineAsset.name;
    21.  
    22.                 foreach (var track in timelineAsset.GetOutputTracks())
    23.                 {
    24.                     var animTrack = track as AnimationTrack;
    25.                     if (animTrack == null)
    26.                         continue;
    27.  
    28.                     var binding = director.GetGenericBinding(animTrack);
    29.                     if (binding == null)
    30.                         continue;
    31.                     var animator = binding as Animator;
    32.                     var gameObject = binding as GameObject;
    33.                     if (animator == null && gameObject != null)
    34.                         animator = gameObject.GetComponent<Animator>();
    35.                     if (animator == null)
    36.                         continue;
    37.  
    38.                     foreach (var clips in animTrack.GetClips())
    39.                     {
    40.                         var animAsset = clips.asset as AnimationPlayableAsset;
    41.                         if (animAsset)
    42.                         {
    43.                             AnimationClip clip = animAsset.clip;
    44.                             logstr += "\n                     animationTrack is (w/ animator): curves: " + UnityEditor.AnimationUtility.GetAllCurves(clip);
    45.                             // ...
    46.          
    47.                         }
    48.                     }
    49.                 }
    50.  
    51.                 // get curves from trackAsset TimelineClips
    52.                 foreach (UnityEngine.Timeline.TrackAsset trackAsset in tracks)
    53.                 {
    54.                     IEnumerable<UnityEngine.Timeline.TrackAsset> childtracks = trackAsset.GetChildTracks();
    55.  
    56.                     logstr += "\n                 trackAsset: " + trackAsset.start + "-" + trackAsset.end
    57.                         + " " + trackAsset.name + " " + trackAsset.outputs + " childtracks: " + childtracks;
    58.  
    59.                     IEnumerable<UnityEngine.Timeline.TimelineClip> clips = trackAsset.GetClips();
    60.  
    61.                     foreach (UnityEngine.Timeline.TimelineClip trackAssetClip in clips)
    62.                     {
    63.                         AnimationClip curves = trackAssetClip.curves;
    64.  
    65.                         logstr += "\n                       trackAssetClip: " + trackAssetClip.animationClip + " " +
    66.                             + trackAssetClip.start + "-" + trackAssetClip.end + ":  " +
    67.                             trackAssetClip.animationClip;
    68.  
    69.                         if (curves == null)
    70.                             logstr += "\n                              curves: null";
    71.                         else
    72.                             logstr += "\n                              curves: " + curves.events;
    73.                     }
    74.                 }
    75.             }
    76.         }
    77.  
    78.         Debug.Log(logstr);
    79.     }
    80.  
    Attached is a screenshot of tracks with recorded animation points at the logged scene - the Debug.Log prints trackAssetClip data, but curves are null.
     

    Attached Files:

  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    TimelineClip.curves is where animation data is stored when animating playable parameters. That's used for animating parameters on custom clips.

    trackAssetClip.animationClip is the animation clip you want in this case. It's just a shortcut for (trackAssetClip.asset as AnimationPlayableAsset).animClip.