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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Get the current clip info on timeline

Discussion in 'Timeline' started by saifshk17, Jul 3, 2023.

  1. saifshk17

    saifshk17

    Joined:
    Dec 4, 2016
    Posts:
    487
    Hi,

    Is there a way to get the timeline's current activation/animation track while it is playing?
    I would like to get the clip.start and clip.end info on the timeline's clip.
    How do I do this?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Playables;
    5. using UnityEngine.Timeline;
    6.  
    7. public class TimelineController : MonoBehaviour {
    8.     public PlayableDirector timeline;
    9.  
    10.     public void Update () {
    11.  
    12.         var asset = timeline.playableAsset as TimelineAsset;
    13.         foreach (var track in asset.GetOutputTracks ()) {
    14.          
    15.             }
    16.         }
    17.  
    18. }
     
  2. Yuchen_Chang

    Yuchen_Chang

    Joined:
    Apr 24, 2020
    Posts:
    111
    The current time of the playing Timeline is
    PlayableDirector.time
    , and the clip's start/end time are
    TrackAsset.start/end
    . So you can search through the start/end, and check if it is playing a certain clip.
     
  3. saifshk17

    saifshk17

    Joined:
    Dec 4, 2016
    Posts:
    487
    But can i get the name of the current trackasset?
     
  4. Yuchen_Chang

    Yuchen_Chang

    Joined:
    Apr 24, 2020
    Posts:
    111
    You can get it by
    track.name
    , just like other UnityEngine.Object.
    (What do you want to achieve?)