Reset timeline from Code?

Hi, I’ve been trying to figure out how to properly reset a timeline that’s half-way through when a player hits the reset button.
At the moment I stop the playable director and set the time to 0. However the objects in the timeline, including particle effects that are being controlled by the Control track, just stay in their current position.
Which is weird on it’s own, but when a player then triggers it again, everything, including the particle effects shoot back to the starting position, leaving a trail. Which is not desirable.

Am I missing a simple Api call that cleanly resets this?

Thanks!

You can use Activation and PostPlaybackState on the Control Track (which would disable the particle system), but otherwise this looks like a bug.

1 Like

I’ve run into this again unfortunately.
It’s actually not only the particles, but anything set by the playable director, that doesn’t get properly reset.
I have an area which gets closed off by a activation track in a Timeline. But after the player crosses it, and restarts the level, I reset the Timeline/PlayableDirector by Stopping it, and setting the time to 0. However the objects stay active and in their last position. The camera that is triggered in that track also stays active.

The only way to restart it, is to trigger the PlayableDirector again.
Perhaps something to do with destroying the playableGraph that’s behind it?

I’ve updated to 2017.3, and the same issues occurs.

A ResetToStartConditions or similar method would be great.

We have the same problem.

It´s not about particles in timeline. If there are particles or not, a timeline updates only the controlled objects, when the timeline is playing. That means, if I say “playableDirector.Stop()” in script. The timeline stops. BUT, the timeline should also jump back to the first frame. That´s the way a “stop” has to work. Maybe an “old” example, but hit stop on a CD Player, resets the player immediately to beginning of the CD. Pause a CD Player holds the position and on Play() the player resumes. Timeline Stop() resets the playableDirector, but the “Frame Update” will only be visible, when Play() is called again. But again, this is not what a user wanted to have when he says “stop()”. If I set time = 0 and say then stop(), it´s the same. The Animations freeze, but some times later, when I call play again, they are realy resetted on screen. But this should happen immediately on “stop()”. Or in other words, the timeline current Frame should not only be updated when in PlayMode, but also in Stop-Mode. May be just one time and not everytime.

Greetings,

Martin

1 Like

Oh wow, I’ve spent about 3 days running through my code to try and figure this out. My issue is that the second time I play the timeline, any script that I want to activate gets ignored. So we can’t play a timeline that has already been played. Ouch!

So for Folks running into this issue :smile: you can just do this:

playableDirector.time = 0;
playableDirector.Stop();
playableDirector.Evaluate();

This will force the playable to Evaluate at time 0 and reset everything.

12 Likes

Would it be possible to share the whole code that achieves this? I’ve been trying for a while and can’t quite get it to work.

I have a timeline that I need to be able to stop and reset to zero.

“At the moment I stop the playable director and set the time to 0” How can this be accomplished?

Edit: ‘Current Time’ is only accessible when the scene is active so it can’t be added as a timeline event as far as I can tell. So I need a small script I can trigger that accomplishes the same thing, resets ‘Current Time’ to 0

Hi, i’m new to timelines and generaly to unity but what about this

pDir.initialTime = 0f;
pDir.time = 0f;

personaly i use this to start a cutscene at a further time (using values > 0 … ;)) if the player wants to restart the race.
that works prety good but is it right ?

nvm, finaly

pDir.time = t;

seams sufficient to do the job. that start the timeline from t seconds.
I just would know if it was a good way to do that…

I just deactivate and reactivate the timeline game object and it properly resets for me.

If there is a chance that it’s already active and I want to replay it then I just use this code:

myTimeline.SetActive(true);
PlayableDirector playableDirector = myTimeline.GetComponent<PlayableDirector>();
playableDirector.time = 0;
playableDirector.Play();

Although, perhaps this is a bit more clear and not redundant:

if(!myTimeline.activeSelf)
  myTimeline.SetActive(true);
else
{
  PlayableDirector playableDirector = myTimeline.GetComponent<PlayableDirector>();
  playableDirector.time = 0;
  playableDirector.Play();
}

Hey

I have a problem with resetting the timeline while having a cinemachine track with a clip.

I reset all my timelines based on my checkpoint system.

I use the solution described above. I use director.Stop(); then director.time = 0f (or duration), then director.Evaluate();

One of my timelines sets a virtual camera live even though it’s not highest priority? If I move the clip on the track away from the beginning, it does not do it. So it seems like a weird bug or maybe my method of using Stop, set time, evaluate is not correct.

The same happens with the rotation of the character object. None of the timelines are playing but it seems like they are so I cannot rotate the character object and cinemachine get stuck in a specific virtual camera.