Search Unity

Set track position in editor via script?

Discussion in 'Timeline' started by artemio_morales, Sep 23, 2019.

  1. artemio_morales

    artemio_morales

    Joined:
    Nov 29, 2015
    Posts:
    19
    Hi there,

    Given a GroupTrack with many child tracks, I'm wondering if it's possible to set the position of a child track within the group via script.

    Basically, I'm looking for the equivalent of GetSiblingIndex() and SetSiblingIndex() for game objects, except for TrackAssets.

    I looked through the Timeline API but was unable to find anything like this. Is this supported? If not, would be awesome to see :)
     
  2. artemio_morales

    artemio_morales

    Joined:
    Nov 29, 2015
    Posts:
    19
    Ok so it's not clean, but after looking into this, I realized you can get all the child tracks of a group, convert that to a list, insert your new track at a specified index, then loop through all of the child tracks, first setting the parent to null, then to the group you want. That should set the parent of all the tracks in the correct order.
     
  3. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    That would be a good API addition. What you can do is get a list of all child tracks using GroupTrack.GetChildTracks().

    Then loop through the list, call track.SetGroup(null), order the list the way you want it, loop through it again and call track.SetGroup(group);
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Ah! Didn't see the second post :)
     
    artemio_morales likes this.