Search Unity

Callback for PlayableClip duplication/copying

Discussion in 'Timeline' started by cp-, Apr 29, 2020.

  1. cp-

    cp-

    Joined:
    Mar 29, 2018
    Posts:
    78
    Hi @seant_unity and thanks for your work on the Timeline!

    Is there any callback we can use for after duplication? I need to duplicate a SerializedObject I AssetDatabase-added to the original PlayableClip and do not want the SO to be referenced in the copied clip but use its own SO.

    I cannot use OnAfterDeserialize() because I cannot access the AssetDatabase functions during serialization time. I thought maybe OnEnable() would work but it seems you do something special after that as the PlayableClip is just an in-memory clone of the clip by that time.
    I can of course use some other function to check if I still need to duplicate the SO but that seems rather hacky and is not reliable.
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    If you only need this to work from editor UI, then yes. You can use a ClipEditor to get a callback when a clip is created, which contains the source clip if it was duplicated/copied.

    An example:

    Code (CSharp):
    1. [CustomTimelineEditor(typeof(CustomPlayableAsset))]
    2. public class CustomPlayableAssetClipEditor : ClipEditor
    3. {
    4.     public override void OnCreate(TimelineClip clip, TrackAsset track, TimelineClip clonedFrom)
    5.     {
    6.         var customPlayableAsset = (CustomPlayableAsset) clip.asset;
    7.         if (clonedFrom != null)
    8.         {
    9.             customPlayableAsset.uniqueGUID = System.Guid.NewGuid();
    10.         }
    11.     }
    12. }
     
  3. cp-

    cp-

    Joined:
    Mar 29, 2018
    Posts:
    78
    Yes, editor-time only is sufficient. Works as intended, thanks!