Skip to main content

DataPrefs

The Luna Replay DataPrefs.Fetch API allows you to cache a value during capture and fetch it during replay.

Unlike barriers this function call order can change between capture and replay.

When to use it

This API can be used if you wish to store some consistent data between capture and replay. Between each launch, this data might vary (i.e. data on disk is different), and the DataPrefs API ensures consistency.

For example, if you are retrieving game data from:

  • A 3rd party library
  • A native extension
  • Game server
  • Device memory/disk

Examples

var fixedValue = Luna.Replay.Api.DataPrefs.Fetch<float>("myKey1", () => {
var value1 = ThirdPartyLibraryCall();
return value1;
});

var anotherValue = await Luna.Replay.Api.DataPrefs.Fetch<float>("myKey2", async () => {
var value2 = await CallToServer();
return value2;
});

var yetAnotherValue = Luna.Replay.Api.DataPrefs.Fetch<int>("myKey3", () => {
var levelNumber = PlayerPrefs.GetInt(level);
return levelNumber;
});

var yetOneMoreValue = Luna.Replay.Api.DataPrefs.Fetch<int>("myKey4", () => {
var gameData = GetSavedGameData();
return gameData;
});

In some scenarios, you may need to request data from the same API multiple times, in which case you cannot use a single Data Prefs variable name.

For example, if your fetch and use data from a server during gameplay, it will not be possible to replay this in Luna Creative Suite and the server's response can also change. Therefore, you can store the response during the time of capture to be used during replays

var charNextPosition = Luna.Replay.Api.DataPrefs.
Fetch<Vector3>($"CharacterPosition{Time.frameCount}", () => {
return Character.GetNextPosition(char);
});
If the plugin is disabled, this API will be ignored.