Search Unity

Get a reference to the bound object of the custom track from PlayableAsset

Discussion in 'Timeline' started by Zwer99, May 8, 2018.

  1. Zwer99

    Zwer99

    Joined:
    Oct 24, 2013
    Posts:
    24
    Hello :)

    I'm creating a custom Timeline-Track/Clip and ran into a little problem: I need a reference to the bound object of the track from my custom clip (which inherits from PlayableAsset).

    So I have the following FacialExpressionClip:

    Code (CSharp):
    1. [Serializable]
    2.     public class FacialExpressionClip : PlayableAsset, ITimelineClipAsset
    3.     {
    4.         [SerializeField]
    5.         [ValueDropdown("GetFacialExpressionNames")]
    6.         private string facialExpression;
    7.  
    8.         private string[] GetFacialExpressionNames()
    9.         {
    10.             //!!!HERE I wanna access the bound object of the track to get all available Facial Expressions
    11.             return new string[] { "a", "b", "c" };
    12.         }
    13.  
    14.         // template ...
    15.  
    16.         // clipCaps ...
    17.  
    18.         // CreatePlayable ...
    19.     }
    Is this somehow possible?

    Thank you very much!
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,110
    It is a bit tricky, because the clip itself is an asset. The binding can change (e.g. two different playable directors playing the same timeline can have different bindings).

    However, there are a couple things you can do. In your track asset, you can override CreateTrackMixer() (called when the graph is compiled) to set properties/fields to store the track (used to look up the binding), or the actual binding itself.

    e.g.

    public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
    {
    foreach (var c in GetClips())
    {
    (c.asset as FacialExpressionClip).parentTrack = this; // this field would be serializable in assets
    (c.asset as FacialExpressionClip).binding = go.GetComponent<PlayableDirector>().GetGenericBinding(this); // not serializable in assets
    }
    return base.CreateTrackMixer(graph, go, inputCount);
    }
     
  3. Zwer99

    Zwer99

    Joined:
    Oct 24, 2013
    Posts:
    24
    Luckily the binding doesn't have to be serializable in my case :)

    So thank you very much - your hint works perfectly!