Creating a Replay System in Unity

A replay system is a great way to let players relive their best (or worst) moments of gameplay, improve their strategy, and more! In this tutorial, you’ll build a simple state-based replay system and learn about how replay systems work. By Teddy Engel.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Using the Counter

Look in both StartReplaying and StartRecording and add this after the call to ResetReplayFrame:

StartReplayFrameTimer();

Next, find UpdateRecording and replace the call to SaveTransforms with this:

if (replayFrameTimer == 0)
{
    SaveTransforms(transforms);
    ResetReplayFrameTimer();
}
--replayFrameTimer;

This code checks if replayFrameTimer is ready for the next save, at zero. If so, you save the transforms and set the timer back to the total length, two.

Now you’ll do the same in UpdateReplaying. Replace the call to LoadTransforms in that method with this:

if (replayFrameTimer == 0)
{
    LoadTransforms(transforms);
    ResetReplayFrameTimer();
}
--replayFrameTimer;

Run the scene, record some gameplay and play it back. Notice the result is still pretty smooth. Update the Replay Frame Length on the Replay Manager component to five and try again. A lot less smooth!
[/spoiler]

Congratulations on completing the tutorial! You now have the power to control time itself!

Where to Go From Here?

You can download the completed project files by clicking the Download Materials button at the top or bottom of the tutorial.

In this tutorial, you’ve learned how to implement a simple state-based replay system along with some small optimizations. There are many interesting places to go from here. You could store your replay information in a file, implement an input-based system or try integrating other components like the Animator.

It’s up to you!

Here are some resources that may help you on your way:

Feel free to comment below if you have any comments or questions! :]

Reference

Replay System Using Unity
Implementing a replay system in Unity and how I’d do it differently next time
Developing Your Own Replay System

Teddy Engel

Contributors

Teddy Engel

Author

Margaret Moser

Tech Editor

Aleksandra Kizevska

Illustrator

Ben MacKinnon

Final Pass Editor

Over 300 content creators. Join our team.