- Home /
Am I using OnPlayableCreate in the wrong way?
Hello,
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.
Answer by seant_unity · Oct 23, 2019 at 03:41 PM
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.
But wont OnBehaviorPlay and OnGraphStart get called at the start of each Clip?? Is there any callback where I can alter the PlayableBehaviors only once in the lifetime of a timeline?
OnGraphStart will get called when the Timeline starts playing, or is scrubbed for the first time. In editor, it can get called frequently because the playable graph is rebuilt when the timeline changes, but at runtime it should only be called when the timeline starts.
Your answer
Follow this Question
Related Questions
Why is FindObjectOfType() called during Camera.Render? It's not in my code. 0 Answers
Peculiar Bleed-through of Exposed References on different Timeline Tracks 2 Answers
Timeline not play animation when evaluate calling manually from script 1 Answer
Is their any support of outlook Calendar in Unity ? 0 Answers
Instruct an animation to jump to specific point in timeline 1 Answer