InMemoryVariableStorage

Class in Yarn.Unity

Inherits from VariableStorageBehaviour

Summary

A simple implementation of VariableStorageBehaviour.

public class InMemoryVariableStorage : VariableStorageBehaviour, IEnumerable<KeyValuePair<string, object>>

Remarks

This class stores variables in memory, and is erased when the game exits.

This class also has basic serialization and save/load example functions.

You can also enumerate over the variables by using a foreach loop:

// 'storage' is an InMemoryVariableStorage
foreach (var variable in storage) {
string name = variable.Key;
System.Object value = variable.Value;
}

Note that as of v2.0, this class no longer uses Yarn.Value, to enforce static typing of declared variables within the Yarn Program.

Fields

NameDescription

Methods

NameDescription

Removes all variables from storage.

returns a boolean value representing if the particular variable is inside the variable storage

Import a JSON string into variable storage, like when loading save game data.

Load JSON data from a file, then deserialize as variables.

Load JSON data from Unity's built-in PlayerPrefs with default playerPrefsKey, and deserialize as variables.

Load JSON data from Unity's built-in PlayerPrefs with defined playerPrefsKey parameter, and deserialize as variables.

Serialize all variables to JSON, then write the data to a file.

Serialize all variables to JSON, then save data to Unity's built-in PlayerPrefs with default playerPrefsKey.

Serialize all variables to JSON, then save data to Unity's built-in PlayerPrefs under playerPrefsKey parameter.

Export variable storage to a JSON string, like when writing save game data.

Retrieves a Value by name.

Last updated

Yarn Spinner® and Secret Lab® are trade marks of Secret Lab Pty. Ltd., and are used by Yarn Spinner Pty. Ltd. under license.