Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

How do I get Clip Timing (TimelineClip) info from PlayableAsset

Discussion in 'Timeline' started by vincismurf, Apr 10, 2018.

  1. vincismurf

    vincismurf

    Joined:
    Feb 28, 2013
    Posts:
    200
    I would like to tie Button's Click Event to a PlayableAsset, which is simple enough, but I noticed that the event is fired for each instance of the Asset on the Playable Track.

    So I was thinking if I had the PlayableAsset's Start/End from the Clip Timing ( TimelineClip data) I could test against the current time of the Director to find which Playable asset I need.

    I didn't see any clear API for getting the TimelineClip data from an Asset.

    Can you help?
     
  2. KapuraIII

    KapuraIII

    Joined:
    Oct 25, 2017
    Posts:
    11
    I had a similar problem, and it doesn't look like the playable asset has any knowledge of the TimelineClip. If you have a reference to the timeline asset itself, you can do something like:
    Code (CSharp):
    1. var tracks = timeline.GetOutputTracks();
    2. foreach (TrackAsset track in tracks)
    3. {
    4.     var clips = track.GetClips();
    5.     foreach (TimelineClip clip in clips)
    6.     {
    7.         if (clip.asset == targetAsset) return clip;
    8.     }
    9. }
    and then read the timing from clip.start and clip.end
     
    davidrochin, lofell and vincismurf like this.
  3. dimmduh1

    dimmduh1

    Joined:
    Feb 5, 2021
    Posts:
    24
  4. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    @dimmduh1 's answer is the proper one as far as getting the information in your playable: you should inject that information in your playable when your create the playable.

    But I'm curious, can you tell me why you want to associate a button to a playable asset, and why it must be different based on time?
     
  5. dimmduh1

    dimmduh1

    Joined:
    Feb 5, 2021
    Posts:
    24
    it's not my code above.

    But I'm writing basic classes to easy create custom timeline tracks
    https://gist.github.com/dimmduh/033acb2dad9f9b4a6532534a2fe0a189