0
Answered
lochmann.android 2 months ago • updated 1 week ago 4

Hey there, what's the best way to restart clocks and timelines? The clock starts to tick as soon as the scene is started, but for our purpose we'd need to reset it to 0 after a while so time can start anew.

I didn't find anything in the docs, so I implemented a method in Timeline which just does :

public void Reset()        
 { 
    time = 0; 
    unscaledTime = 0;
 }

Seems to work from first glance, is it ok, or will I end in hell?

Chronos Version: 2.2
Unity Version: 5.6.0p1
Answered

That's an interesting question. May I ask what is your exact use case? Maybe I'd be able to help more.

The answer is: it depends on what you're trying to do.

If you're trying to entirely reset the timeline, you'll want to expand that reset method. It should include, among other things:

timeScale = lastTimeScale = 1;
previousDeltaTimes.Clear();  
if (recorder != null) recorder.Reset();

If you want to reset the occurrences as well, you should add:

occurrences.Clear(); 
handledOccurrences.Clear(); 
nextForwardOccurrence = null; 
nextBackwardOccurrence = null;

Even with all these resets, there might be hard to debug side effects due to the attached components. The sure-fire way to entirely reset a timeline is to destroy the timeline game object, then add it again, with the same settings.

Again, if you can tell me a bit more about your setup, I might be able to help you find a better way.

If not, the previous additions should make your reset method more robust.

Cheers,

Lazlo

Hey Lazlo, thanks for the response.

In our project the player will be stuck in a time loop which resets periodically and starts anew, so I thought I'd just reset the timeline, but in the meantime I also came to the conclusion that it is better to destroy and readd the whole timeline and/or even the complete scene.

Thanks again, I might come back with more questions :)

Martin

Hi Martin,

Just to let you know that the next version will include an experimental Reset() method that does what was described here.

Hey Lazlo, awesome! That will for sure come in handy :)