Search Unity

How to get the TimelineClip for a PlayableBehaviour?

Discussion in 'Timeline' started by mhofer, Nov 7, 2017.

  1. mhofer

    mhofer

    Joined:
    Aug 30, 2017
    Posts:
    18
    I have a PlayableAsset that puts a PlayableBehaviour on a Timeline. Now I would like to automatically change the duration of the resulting TimelineClip in CreatePlayable() in my PlayableAsset.

    How do I get to the resulting TimelineClip?
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    There's no reference to the TimelineClip from a PlayableAsset. However, if you have a custom track, you can override CreateTrackMixer(), and iterate through the clips of the track there.

    The track mixer is created prior to the clip playables, so you should be able to make any adjustments you need there.
     
  3. mhofer

    mhofer

    Joined:
    Aug 30, 2017
    Posts:
    18
    Thanks! Now I made it work with a custom track!
     
  4. bonzajplc

    bonzajplc

    Joined:
    Jul 30, 2017
    Posts:
    2
    How can I iterate through my type of behaviors to access their data during building stage? I can't find any example on how to get externally to actual behaviors and their data (not the templates).
     
  5. bonzajplc

    bonzajplc

    Joined:
    Jul 30, 2017
    Posts:
    2
    I solved it.
    You just to have iterate through the assets.

    Code (CSharp):
    1.        //Timeline
    2.         string[] guids = AssetDatabase.FindAssets("t:TimelineAsset");
    3.         foreach (string guid in guids)
    4.         {
    5.             TimelineAsset timeline = (TimelineAsset)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), typeof(TimelineAsset));
    6.  
    7.             foreach( var track in timeline.GetOutputTracks() )
    8.             {
    9.                 foreach (var clip in track.GetClips())
    10.                 {
    11.                     if( clip.asset.GetType() == typeof(MyType) )
    12.                     {
    13.                         MyType mt = (MyType)clip.asset;
    14.                     }
    15.                 }
    16.             }
    17.         }
    18.  
     
    IvanIvanovP3 likes this.
  6. mhofer

    mhofer

    Joined:
    Aug 30, 2017
    Posts:
    18
    The problem with this is that it won't build because AssetDatabase is a part of UnityEditor and that's simply not available in a build... :/
     
  7. 1257961942

    1257961942

    Joined:
    Jul 22, 2017
    Posts:
    5
    you can use Resource or AssetBundle to load.Then use this way to do what you want