Scrubbing a timeline in code during play mode

I’m trying to manually scrub a timeline from a script by setting PlayableDirector.time. I have a Timeline panel open in the editor and I can see the playhead moving around properly when I do this, but none of the tracks appear to update.

If I grab the playhead in the timeline and move it around in there, the game objects update as expected, but not when I set it from the script. I tried setting the timeUpdateMode to Manual and calling PlayableDirector.Play() after setting the time, but it doesn’t seem to do anything.

The documentation says that when using Manual update mode, “You need to manually call PlayerController.Tick with your own deltaTime”, but I don’t actually have any idea what PlayerController is and doesn’t appear to be a member variable of PlayableDirector. I might be chasing down the wrong path with this anyway.

I guess I just need to know how to force a DirectorPlayable to update everything based on a manually set time.

You will need to do playableDirector.Evaluate(); each frame you want to update it, which is slower than regular playback.

Or, a bit of a workaround, you could do
playableDirector.timeUpdateMode = DirectorUpdateMode.GameTime; // or anything other than manual
playableDirector.RebuildPlayableGraph();
playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(0); // prevent time from advancing
playableDirector.Play();

Then it will evaluate everyframe and you can change the time at will.

In Manual mode, the update doesn’t occur - not sure if it’s a bug or a feature… this is a workaround to get the behaviour you expect.

4 Likes

Was this in regards to having something like a slider and being able to scrub forward and backwards through a Timeline play sequence? Because that’s something I’m looking to do, but cannot find good information or references on whether it even works. As you mentioned, in the Editor I can scrub the Timeline window playhead and watch the animations/sequences happen, but I need the user to be able to have such control. It can be done with just the Animator control, but then it looses all the other benefits from the Timeline setup such as turning object visibility on and off and syncing with audio effects. Thank you.

Hey man, I was just dealing with this and found the answer here [ https://discussions.unity.com/t/719918

I]( https://discussions.unity.com/t/719918 )t works exactly as proposed :smile:

Hello Kenneth, I think you pasted the wrong link.
Maybe you still have it?, I want to control my timeline sequence with a slider too, but I cant found information.

Hey there, I think I did link the wrong post. Here’s the solution:6276245--693332--tmscb.png