Skip to main content

Saving and Loading Variables

EasyTalk provides an easy way to save and load variable values of a Dialogue during runtime if you want to maintain the Dialogue state across game restarts.

Saving Variable Values

To save variable values, just call the method SaveVariableValues() on the Dialogue Controller you want to save variable values for.

myDialogueController.SaveVariableValues();

You can provide a file name prefix to append to the JSON file which will be saved:

string playthroughID = " 12345";
myDialogueController.SaveVariableValues(playthroughID);

In the above example, if the controller is set to use a Dialogue asset called 'mainStory', the JSON file for saved variable values will be '12345_mainStory.json'.

By default, variable values will be saved to a JSON file, but alternatively, you can save to PlayerPrefs instead by passing true as the second parameter to the SaveVariableValues method:

//Variable states are saved to PlayerPrefs instead of a JSON file.
string playthroughID = " 12345";
myDialogueController.SaveVariableValues(playthroughID, true);

Loading Variable Values

Similar to saving variable values, you can load them using the LoadVariableValues method:

myDialogueController.LoadVariableValues();

You can also provide a prefix:

string playthroughID = " 12345";
myDialogueController.LoadVariableValues(playthroughID);

And you can load from PlayerPrefs instead of a JSON file:

string playthroughID = " 12345";
myDialogueController.LoadVariableValues(playthroughID, true);