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.
  2. Dismiss Notice

[Sequences] start, end, duration of timeline sequences

Discussion in 'Virtual Production' started by zt3ff3n, Dec 13, 2021.

  1. zt3ff3n

    zt3ff3n

    Joined:
    Feb 19, 2016
    Posts:
    36
    I need to access the 'start, end, duration' info from one of my "Shot Sequences" which are in turn "children" of the Master sequence. How can I reference their data - and or manipulate it from C#.
     

    Attached Files:

  2. ellka

    ellka

    Unity Technologies

    Joined:
    Jun 17, 2019
    Posts:
    70
    Hello! On the "TimelineSequence" object you can access those information and change them in C#. If you provide a bit more context on your use case I can help you with code examples if needed!
     
    marief_unity likes this.
  3. zt3ff3n

    zt3ff3n

    Joined:
    Feb 19, 2016
    Posts:
    36
    I'm am making an ui runtime timeline clone. Ideally I would reference the master sequence or sequence filter, and loop through the shot sequences that it contains - then placing ui images according to their start, end and duration.

    In this example, I've added them manually to a _playableDirectors list as I've been experimenting with different ideas.

    Code (CSharp):
    1.  
    2. foreach (var child in _playableDirectors)
    3. {
    4.     float starttime = (float) child.initialTime;
    5.     float duration = (float) child.duration;
    6.  
    7.     float endtime = starttime + duration;
    8.     string name = child.name;
    9.     float totalwidth = timelineParent.GetComponent<RectTransform>().rect.width;
    10.     Debug.Log("name: " + name + "starttime: " + starttime + " endtime: " + endtime + " duration: " + duration +
    11.               " totalwidth: " + totalwidth);
    12.  
    13.     Instantiate(shotIndicator, timelineParent).GetComponent<RectTransform>().anchoredPosition =
    14.         new Vector2(starttime, 0);
    15.  
    16. }
    It works with end-time and duration, but start-time is giving me a harder time..
    //edit. I'm aware " new Vector2(starttime, 0);" wouldn't work like that.. ;)
     
  4. ellka

    ellka

    Unity Technologies

    Joined:
    Jun 17, 2019
    Posts:
    70
    What kind of objects the _playableDirectors list contains?
     
  5. zt3ff3n

    zt3ff3n

    Joined:
    Feb 19, 2016
    Posts:
    36
    As of now, I'm using this.
    public PlayableDirector[] _playableDirectors;

    But it seems like I should be using some of the other classes/objects, honestly I'm a bit lost navigating the timeline jungle right now... Ideally I'd just open a public variable to get the master sequence or sequence filter and get the list of sub-sequences / shots through that.
     
  6. ellka

    ellka

    Unity Technologies

    Joined:
    Jun 17, 2019
    Posts:
    70
    If it is really on MasterSequence and sequences objects that you want to iterate on and display, then you can get MasterSequence assets via the AssetDatabase API. And from there iterate on children and start/end/duration values.

    You could actually do it from Timeline as well. But it's not the PlayableDirector info that you need but the Timeline asset that is bind to it and its tracks and clips.

    Using Sequences API (it's pseudo code, I didn't test it):
    Code (CSharp):
    1.  
    2. var masterSequence = AssetDatabase.LoadAssetAtPath<MasterSequence>("Assets/Sequences/MyMasterSequence.asset");
    3.  
    4. var rootSequence = masterSequence.rootSequence;
    5. // Here you can already check rootSequence.start/end/duration
    6.  
    7. // Or loop over its children sequence:
    8. foreach (var childSequence in rootSequence.children)
    9. {
    10.     var timelineSequence = childSequence as TimelineSequence;
    11.     // Access timelineSequence.start/end/duration...
    12.     // Or loop through its children again if you need....
    13. }
    Using timeline (again, I didn't test):
    Code (CSharp):
    1.  
    2. // Assuming you have a playable director in hand:
    3. var timeline = playableDirector.playableAsset as TimelineAsset;
    4.  
    5. // Or, if you have a TimelineSequence object:
    6. var timeline = myTimelineSequence.timeline;
    7.  
    8. // Or, you can even get a TimelineAsset directly from the AssetDatabase like I did above to retrieve a MasterSequence:
    9. var timeline = AssetDatabase.LoadAssetAtPath<TimelineAsset>("Assets/myTimelineAsset.playable");
    10.  
    11. foreach (var track in timeline.GetOutputTracks())
    12. {
    13.     if (!track is EditorialTrack)
    14.         continue;
    15.  
    16.     foreach (var clip in track.GetClips())
    17.     {
    18.         // Here get clip.start/end/duration;
    19.     }
    20. }
    I don't know if it help having those examples... but I hope.
    Maybe it will help providing more precise questions if you have some. Don't hesitate!
     
  7. zt3ff3n

    zt3ff3n

    Joined:
    Feb 19, 2016
    Posts:
    36
    Thank you so much Elka! This works like a charm.
    As a side note, we're very excited about the Sequences workflow and your efforts with it. I hope you're still actively developing it and have more examples and doc content in the pipeline. As mentioned, we're working to enable some runtime editing, creation and manipulation of sequences - examples or articles exploring that sort of usecase is super interesting. :)
     
    ellka likes this.
  8. ellka

    ellka

    Unity Technologies

    Joined:
    Jun 17, 2019
    Posts:
    70
    I'm happy that helped!

    We are still actively developing it yes, no worries!
    And we are happy to get your feedback! It's actually interesting to know your runtime usage, I think it is the first time we have such use case (most users are editor only, at least to build their editorial with Sequences). I hope you'll find what you need!