Checkpoints
Checkpoints save random number state during capture and restore them during replay.
At the moment, checkpoints do not support System.Random.
Unlike barriers this function's call order can change between capture and replay.
When to use it
This API can be used at the end of multiple asynchronous operations executed in parallel to maintain the random number sequence.
Because these operations can end in any order and then call UnityEngine.Random
, the random sequence can be different between capture and replay. Checkpoints allow you to accommodate for such scenarios.
Example - Async loading
IEnumerator Start()
{
var uwr = UnityWebRequestAssetBundle.GetAssetBundle("http://server/myBundle.unity3d");
yield return uwr.SendWebRequest();
// Get an asset from the bundle and instantiate it.
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr);
var loadAsset = bundle.LoadAssetAsync<GameObject>("Assets/Players/MainPlayer.prefab");
yield return loadAsset;
Checkpoint.Random("uniqueCheckpointName");
Instantiate(loadAsset.asset);
// Do random stuff using UnityEngine.Random class.
}
Example - introducing optional random states
public void AnimationSequence() {
int animationMode;
if (randomMode) {
animationMode = Random.Range(minValue ,maxValue)
} else {
animationMode = Character.GetMode();
}
Character.PlaySequence(animationMode);
Checkpoint.Random("animationMode");
}