Am I using OnPlayableCreate in the wrong way?


I have a custom timeline track where in I have some complex behavior. So I have a requirement where I want to setup certain things in each clip on the track at the time when the this timeline is assigned to the playable director component to play.
So basically I want this to happen only once, when the timeline first starts playing. Not every frame or not when each clip starts.

Thats why I used the OnPlayableCreate override to do it. But I somehow always get a null reference when I try to extract the behavior from the playable.

    public override void OnPlayableCreate(Playable playable)
        int inputCount = playable.GetInputCount();

        for (int i = 0; i < inputCount; i++)
            float inputWeight = playable.GetInputWeight(i);
            ScriptPlayable<TestyBehaviour> inputPlayable = (ScriptPlayable<TestyBehaviour>)playable.GetInput(i);
            TestyBehaviour input = inputPlayable.GetBehaviour();

            // THIS LINE ALWAYS LOGS 'TRUE'!!
            Debug.Log(input == null);

This a simple OnPlayableCreate override I made in an empty project. The ‘input’ always is null.
Is this how its supposed to be or am I using it wrong? Everything else works well, so I’m quite certain that my custom track is setup properly.

Yes this is expected behaviour. In OnPlayableCreate the number of inputs may have been set through the Playable.Create call, but there will be no inputs connected yet. You may want to use OnGraphStart() or OnBehaviourPlay() instead.