Search Unity

Accessing Non-CustomPlayable Clips like Activation, Animation etc

Discussion in 'Timeline' started by hoperin, Jul 31, 2018.

  1. hoperin

    hoperin

    Joined:
    Feb 9, 2014
    Posts:
    52
    So I'm making a system that copies over clips of each type and duplicates them on new timelines. I haven't found a way to duplciate them without targeting the specific type of clip, which has worked fine for all my custom playable clip types, but I'm running into a big snag with the standard types (ActivationClip, AnimationClip, AudioClip, etc)

    Here's how I'm copying my custom playable types:
    Code (CSharp):
    1.  case "CAM_ShakeTrack":
    2.                 newClip = targetTrack.CreateClip<CAM_ShakeClip>();
    3.  
    4.                 CAM_ShakeClip csclip = newClip.asset as CAM_ShakeClip;
    5.                 CAM_ShakeClip csoldClip = copyClip.asset as CAM_ShakeClip;
    6.  
    7.                 csclip.template.CamShakeTarget = csoldClip.template.CamShakeTarget;
    8.                 csclip.template.ShakeAmount = csoldClip.template.ShakeAmount;
    9.                 csclip.template.ShakeDuration = csoldClip.template.ShakeDuration;
    10.                 csclip.template.Smooth = csoldClip.template.Smooth;
    11.                 csclip.template.SmoothAmount = csoldClip.template.SmoothAmount;
    12.                 csclip.template.played = csoldClip.template.played;
    13.  
    14.                 newClip.start = targetClip.start + timeOffset;
    15.                 newClip.duration = copyClip.duration;
    16.                 return;
    but when I try the same type of code of type AnimationClip I get a missingly assembly reference error.
    Code (CSharp):
    1. Assets/Scr_TimelineUpdateManager.cs(570,17): error CS0246: The type or namespace name `ActivationClip' could not be found. Are you missing an assembly reference?
    Investigating, I found that the tracks of AnimationTrack type debug their types as UnityEngine.Timelime.AnimationTrack instead of just AnimationTrack, so I tried targeting the clips as UnityEngine.Timelime.AnimationClip type, but still no dice.

    This attempt:
    Code (CSharp):
    1.  case "UnityEngine.Timeline.ActivationTrack":
    2.  
    3.                 newClip = targetTrack.CreateDefaultClip();
    4.  
    5.               // niether of these working
    6.               //  ActivationClip acClip = newClip.asset as ActivationClip;
    7.               //  ActivationClip acOldClip = copyClip.asset as ActivationClip;
    8.               UnityEngine.Timeline.ActivationClip acClip = newClip.asset as UnityEngine.Timeline.ActivationClip;
    9.               UnityEngine.Timeline.ActivationClip acOldClip = copyClip.asset as UnityEngine.Timeline.ActivationClip;
    10.              
    11.                 newClip.start = targetClip.start + timeOffset;
    12.                 newClip.duration = copyClip.duration;
    13.  
    14.                 //+ access other things within clip
    15.  
    16.                 return;
    returns this error:
    Code (CSharp):
    1. Assets/Scr_TimelineUpdateManager.cs(586,38): error CS0234: The type or namespace name `ActivationClip' does not exist in the namespace `UnityEngine.Timeline'. Are you missing an assembly reference?
    Am I really just missing a different assembly reference of is there a different way needed to target these clip types?

    Thanks!
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    They aren't named clip, they are named with a postfix of 'PlayableAsset'. AnimationPlayableAsset, AudioPlayableAsset, etc...

    You can use reflection as well to get the types for any clips you are using: clip.asset.GetType(), or even try using EditorUtility.CopySerialized() to copy the values;

    The catch here is copying animation clips that are recordable - the new versions will not be and will refer to the original timeline clip animation.

    Hope that helps
     
    hoperin likes this.