Search Unity

Custom track - object binding

Discussion in 'Timeline' started by zyeurgh, Mar 30, 2017.

  1. zyeurgh

    zyeurgh

    Joined:
    Nov 2, 2012
    Posts:
    6
    Hello,

    I have created a custom playable / playableasset to send events to wwise (for audio). Setting an ExposedReference in that playable works well to reference which object the sound should be played on.
    But I was wondering, instead of specifying the game object in each playable, how to specify the game object at the track level. So that each playable on that track could get that game object, a bit like on an animation track, all anim clips will play on the same object, specified at the track level.

    I created a custom track to receive the new type of TrackClip but I'm not sure where to go from there to create the necessary binding.
    Any pointers?

    Thanks!
     
  2. julienb

    julienb

    Unity Technologies

    Joined:
    Sep 9, 2016
    Posts:
    123
    You can use the TrackBindingType attribute to specify your custom track binding. You can not only choose a GameObject as your binding type, but also a component or an asset.

    Code (CSharp):
    1. [TrackBindingType(typeof(Material))]
    2. public class MyTimelineTrack : TrackAsset
    3. {
    4.     public override PlayableHandle CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
    5.     {
    6.         return base.CreateTrackMixer(graph, go, inputCount);
    7.     }
    8. }
    Also, in a playable, in order to get access to the track's binding, you can override ProcessFrame and cast the playerData argument:

    Code (CSharp):
    1. public override void ProcessFrame(FrameData info, object playerData)
    2. {
    3.     Material mat = playerData as Material;
    4.     //...
    5. }
    6.  
     
  3. zyeurgh

    zyeurgh

    Joined:
    Nov 2, 2012
    Posts:
    6
    Awesome, thanks!
     
  4. mhofer

    mhofer

    Joined:
    Aug 30, 2017
    Posts:
    18
    Hey, is there any way to set the object that it's bound to automatically on track creation? OnEnable seems like a good place, but I can't get to the director from there, can I? :/