Search Unity

Creating Child Tracks (via Scripting)

Discussion in 'Timeline' started by ToddRivers, Oct 23, 2018.

  1. ToddRivers

    ToddRivers

    Joined:
    Mar 15, 2013
    Posts:
    17
    Hey!

    I'm trying to make custom child/parent tracks for the timeline which behave similar to the Animation Track, i.e. a parent root track with the binding and then child tracks for different layers of animation.

    I'm using the CreateTrack<T> function on the parent TimelineAsset to create a new track on a specified parent but it throws an exception:
    InvalidOperationException: Cannot assign a child of type T to a parent of type T

    Where T is the type of my track asset.
    Is there an attribute or something I need to do to allow custom tracks to be able to be children of other tracks??

    Also Ideally I'd be able to add a custom context menu item to allow creating child tracks in the same way the 'Add Override Track' menu works for Animator Tracks (see below).
    How is this done? The usual way of adding a [MenuItem] / [ContextMenu] attribute doesn't seem to work for timelines?

    Thanks!


    upload_2018-10-23_11-30-14.png
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Unfortunately, it's not possible to make child tracks for custom tracks. It's on our roadmap to expose, but for the time being animation tracks (and, technically, group tracks) are the only tracks that support child tracks.
     
  3. ToddRivers

    ToddRivers

    Joined:
    Mar 15, 2013
    Posts:
    17
    Cheers for the quick reply!
    Argh I thought that might be the case. Ok fingers crossed its not too far off, would be a super useful feature :)

    I've managed to set a tracks parent manually using reflection so will try and work with that for the moment.
     
  4. atranson

    atranson

    Joined:
    Dec 3, 2019
    Posts:
    6
    @seant_unity Any update on this specific feature ? :)

    I checked out the 1.4.0-preview.1 just now but it appears that track's parent setter or AddChild are still internal methods. Same for MenuEntryAttribute which would come in handy if we were to create custom tracks that allow child tracks.
     
  5. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
  6. atranson

    atranson

    Joined:
    Dec 3, 2019
    Posts:
    6
    Thanks for your response!

    It seems I missed that ILayerable interface in 2019.3, it looks great! Thanks for the link, I checked out the LayeredTracks example, it's a perfect starting point for what I want to achieve. :)