Skip to main content

Barriers

Barriers record and restore game state according to the options provided, and they can be used at the end of asynchronous events, in order to restore a recorded state. For example, you can use a barrier at the end of a preloader screen.

Barriers require the same execution order during capture and replay.

Random State#

BarrierOptions.RandomState

The internal UnityEngine.Random class state will be recorded during capture and restored during replay at the point barrier is called. After this barrier, the same random numbers sequences will be generated when random numbers are taken from UnityEngine.Random.

Frames#

BarrierOptions.Frames

The barrier type is used to synchronise frames at specific moments in code. This becomes especially useful when certain parts of the capture may take less or more time when replayed.

Consider a preloader which may take more or less time on different platforms and devices.

  • Preloader takes longer to load during replay - the number of frames recorded at the barrier will be higher in the replay than in the capture. In this case, the frames will not be restored and the replay will continue from where the barrier was set.
  • Preloader takes longer to load during capture - the number of frames recorded at the barrier will be lower in the replay than in the capture. In this case, all frames until the barrier will be skipped and the replay will continue from here.

Example#

void Update() {
if (loadScene == false) {
loadScene = true;
StartCoroutine(LoadNewScene());
}
if (loadScene == true) {
// Loading
}
}
IEnumerator LoadNewScene() {
yield return new WaitForSeconds(3);
AsyncOperation async = Application.LoadLevelAsync(scene);
while (!async.isDone) {
yield return null;
}
// Preloader barrier
Barrier.Set("Preloader", BarrierOptions.Frames|BarrierOptions.RandomState);
}
}