Search Unity

Way to clear timeline of clips while keeping tracks

Discussion in 'Timeline' started by Romano, Jun 13, 2020.

  1. Romano

    Romano

    Joined:
    Nov 27, 2013
    Posts:
    76
    Hi there, just wondering if anyone knows of a way to delete all clips and markers in a timeline while keeping the tracks? My aim is to duplicate a timeline so I can reuse the tracks and add new clips and I'm trying to avoiding having to recreate all the tracks with the same names.

    Thanks!
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    From script or the from the UI? From the UI, you can use the selection tools to select all clips and markers (either click/drag, or the context menu off the playhead).

    Although it might be easier to script something. Here's a script to demonstrate how to do it.

    Code (CSharp):
    1.     [MenuItem("Timeline/Delete All Clips and Markers")]
    2.     public static void DeleteAll()
    3.     {
    4.         var asset = TimelineEditor.inspectedAsset;
    5.         if (asset == null)
    6.             return;
    7.        
    8.         foreach (var track in asset.GetRootTracks())
    9.         {
    10.             var clips = track.GetClips().ToArray();
    11.             var markers = track.GetMarkers().ToArray();
    12.             foreach (var c in clips)
    13.                 asset.DeleteClip(c);
    14.             foreach (var m in markers)
    15.                 track.DeleteMarker(m);
    16.         }
    17.        
    18.         TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);
    19.     }
    20.  
     
  3. Romano

    Romano

    Joined:
    Nov 27, 2013
    Posts:
    76
    Thanks very much, this is great! I was just looking for any built-in way to do it, but this looks perfect. I found that selecting within the UI worked, but only on clips. If I had anything recorded I had to convert it to a clip first or it would just delete the whole track when I tried to delete it, which seemed a bit too fiddly to be the only way to do it.

    Thanks a lot! :)
     
  4. Romano

    Romano

    Joined:
    Nov 27, 2013
    Posts:
    76
    Hey there, I couldn't get the code to work. It runs fine and I ran the debugger to make sure it was finding the asset. It's finding the correct asset fine, but when I look in Visual Studio Code's debugger it shows there are no clips to delete:
    upload_2020-6-15_23-2-40.png
    The selected timeline definitely has clips on it:
    upload_2020-6-15_23-9-36.png

    Is there something daft I'm doing or some quirk I need to work around?
    Thanks!
     
  5. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    My mistake, use asset.GetOutputTracks instead of asset.GetRootTracks in the script.
     
  6. Romano

    Romano

    Joined:
    Nov 27, 2013
    Posts:
    76
    That works perfectly, thanks so much!