How To Reset/Restart A Unity Timeline

Today I want to quickly show how you can reset or restart a Timeline, since there doesn’t seem to be an official method for it yet.

Today’s Objective: Reset and restart a timeline mid-play using code, so that it restarts whenever you die to the dog.

The Timeline:

When the player passes a certain invisible trigger collider, the timeline is started and the dog spawns and runs to the right after a short delay. If the dog touches the player, the player dies and is respawned prior to the timeline starting.

The Problem:

Since Timelines/Playable Director’s currently have no in-built method to reset them, without making a solution myself, I have 2 options.

I can either keep the timeline playing, or “Stop” it which is actually just a pause, leaving the objects in place. Neither of these suit my needs and would not work for my game.

The Solution:

What I want is for the timeline (and therefore, the dog) to be reset on death, so that it vanishes until I pass the trigger again, restarting it.

The Code:

The code for this is pretty simple, comprising of 3 commands to the PlayableDirector component:

Note: Some of you may have noticed one problem which still remains in this solution.

While the dog (and all other timeline objects) are being reset and restarted correctly, there is a split-second when the Timeline restarts where the objects (like the dog) are still in their previous position from the last Timeline play.

I haven’t yet found a solution to fix this, but I haven’t been working on it long, so I will update this post if I find a solution.

--

--

--

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Journey not the Destination

Building a Progressive Web App with PWABuilder!

To future me, here is the way to set JAVA_HOME

pattern_create.rb remake in Python3 (0x1)

Forthbox NFTs and Metabox

Echo VR | Ending Support for Windows 7

Cozy Collecting, Case Study: Getting a Decade’s Worth of Weather Data in R

The Future of Low-Code and No-Code Development | Seamgen Blog

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vincent Taylor

Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.

More from Medium

Balancing Static & Dynamic Objects when Baking In Unity

Adding Damage for the Propane Tank Explosions

Spawning Objects in Unity Without the Clutter

Using Another Coroutine to Get The Timing Right With Powerups — Unity