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

Hello :slight_smile:

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:

[Serializable]
    public class FacialExpressionClip : PlayableAsset, ITimelineClipAsset
    {
        [SerializeField]
        [ValueDropdown("GetFacialExpressionNames")]
        private string facialExpression;

        private string[] GetFacialExpressionNames()
        {
            //!!!HERE I wanna access the bound object of the track to get all available Facial Expressions
            return new string[] { "a", "b", "c" };
        }

        // template ...

        // clipCaps ...

        // CreatePlayable ...
    }

Is this somehow possible?

Thank you very much!

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().GetGenericBinding(this); // not serializable in assets
}
return base.CreateTrackMixer(graph, go, inputCount);
}

2 Likes

Luckily the binding doesn’t have to be serializable in my case :slight_smile:

So thank you very much - your hint works perfectly!