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.
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);
}
}
Time
BarrierOptions.Time
This option can be used only if BarrierOptions.Frames
is used. As a result of applying this option during Replay, Time values will jump to a barrier moment on Capture. If it's not applied, Time values will not be affected by barriers.