Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Reordering tracks via script

Discussion in 'Timeline' started by Midonk, Jul 6, 2022.

  1. Midonk

    Midonk

    Joined:
    Oct 8, 2018
    Posts:
    35
    Currently working on an automation script and I was wondering if there is a way to reorder the tracks as we do manually in the Timeline window
     
  2. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    Do you mean tracks overall? Or override tracks within an animation track? E.g. TrackAsset has a m_clips (list of tracks) - I assume you reorder it there.

    You then need to do something like EditorUtility.SetDirty(...) to mark it as modified, and AssetDatabase.SaveAssets() to actually write the changes to disk. See this thread for some timeline automation code https://forum.unity.com/threads/how...sequences-automatically.1297773/#post-8243106
     
  3. Midonk

    Midonk

    Joined:
    Oct 8, 2018
    Posts:
    35
    Ok, excuse me, let me clarify this. I want to, for example, take one entire track and place it from below to above another track (like a kind of index change). But everything I am able to get is an Enumerable<TrackAsset>...
     
  4. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    I puked around the docs etc too, and could not find a public api either. There are classes under unity editor that provide utility functions, but I could only find things like create and delete (and create gave no control over position).
     
  5. Midonk

    Midonk

    Joined:
    Oct 8, 2018
    Posts:
    35
    Erf...ok well I went for a reflection solution (setting m_Tracks for TimelineAsset or m_Children for TrackAsset) as I'm gonna use this in editor that should be fine but if someone ever find an easier yet more elegant way to do this, I would be interested