> For the complete documentation index, see [llms.txt](https://docs.yarnspinner.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yarnspinner.dev/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage.md).

# InMemoryVariableStorage

Class in [Yarn.Unity](/2.0/api/csharp/yarn.unity.md)

Inherits from [`VariableStorageBehaviour`](/2.0/api/csharp/yarn.unity/yarn.unity.variablestoragebehaviour.md)

## Summary

A simple implementation of VariableStorageBehaviour.

```csharp
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

| Name                                                                                                                             | Description |
| -------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| [showDebug](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.showdebug.md)       |             |
| [TypeMappings](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.typemappings.md) |             |

## Methods

| Name                                                                                                                                                                           | Description                                                                                                           |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------- |
| [Clear()](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.clear.md)                                                           | Removes all variables from storage.                                                                                   |
| [Contains(string)](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.contains.md)                                               | returns a boolean value representing if the particular variable is inside the variable storage                        |
| [DeserializeAllVariablesFromJSON(string)](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.deserializeallvariablesfromjson.md) | Import a JSON string into variable storage, like when loading save game data.                                         |
| [GetDebugList()](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.getdebuglist.md)                                             |                                                                                                                       |
| [LoadFromFile(string)](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.loadfromfile.md)                                       | Load JSON data from a file, then deserialize as variables.                                                            |
| [LoadFromPlayerPrefs()](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.loadfromplayerprefs-1.md)                             | Load JSON data from Unity's built-in PlayerPrefs with default playerPrefsKey, and deserialize as variables.           |
| [LoadFromPlayerPrefs(string)](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.loadfromplayerprefs-2.md)                       | Load JSON data from Unity's built-in PlayerPrefs with defined playerPrefsKey parameter, and deserialize as variables. |
| [SaveToFile(string)](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.savetofile.md)                                           | Serialize all variables to JSON, then write the data to a file.                                                       |
| [SaveToPlayerPrefs()](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.savetoplayerprefs-1.md)                                 | Serialize all variables to JSON, then save data to Unity's built-in PlayerPrefs with default playerPrefsKey.          |
| [SaveToPlayerPrefs(string)](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.savetoplayerprefs-2.md)                           | Serialize all variables to JSON, then save data to Unity's built-in PlayerPrefs under playerPrefsKey parameter.       |
| [SerializeAllVariablesToJSON(bool)](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.serializeallvariablestojson.md)           | Export variable storage to a JSON string, like when writing save game data.                                           |
| [SetValue(string,bool)](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.setvalue-3.md)                                        |                                                                                                                       |
| [SetValue(string,float)](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.setvalue-2.md)                                       |                                                                                                                       |
| [SetValue(string,string)](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.setvalue-1.md)                                      |                                                                                                                       |
| [TryGetValue(string,T)](/2.0/api/csharp/yarn.unity/yarn.unity.inmemoryvariablestorage/yarn.unity.inmemoryvariablestorage.trygetvalue.md)                                       | Retrieves a `Value` by name.                                                                                          |
