How to Save and Load Player Data

The data in any experience such as variable values like Hitpoints/Money, whether collectible objects have been picked up, or the Player's positon/rotation can be saved to the current player's account. That means if play an experience with save data, log out of your account for six months, log back in, and load the same game, your save data would still exist! If you want, check out the demo experience showing basic and advanced save data setups.

Saving simple data like the value of a variable is very easy to set up, since it uses only two events to save and load. That set up shown in the first scene of the demo experience. Saving more data, like if collectible objects in a scene have been picked up, the state of variables in a HUD, or the player's position/rotation takes a bit more work. The same goes with setting up a system to clear save data. All of those are shown in the second scene of the demo experience.

How to Save Variable Data to a Player's Account

You can save a variable's data, and load it when playing again, with two simple events on a button. To create a variable with a save button:

  1. Add a variable and several buttons that can change the variable's value.

  2. Add another button that will save the variable's data.

  3. On the Save button, add the following event:

On: Interaction Start
Then: Experience
Set Save Data
a. Select "Add Field"
b. Name the Save Data (eg. Money or Hitpoints)
c. Select the Parameter button -> [ ]
d. Choose "Other Object"
e. Select the Variable

Save Data Event

When clicked, then the save button will save the variable's data to the player's account.

To have it load the data when the experience is played again, you just need one more event on the save button:

On: Awake
Then: Other Object -> Select the Variable
a. Select "Set To" for the Variable's action
b. Select the Parameter button -> [ ]
c. Select "Experience"
d. Select "Save Data"
e. Enter the name of the Save Data you want to load

Load Data Event

When the experience starts, the variable will immediately be set to the saved data value.

How to Save, Load, and Clear Multiple Data Values

The second scene in the Demo: Saving Player Data experience shows a scene that saves multiple data values including hitpoints, money, the player's position and rotation, and the state of collectible items. It also contains a button to clear the saved data and reset the scene.

The save button in the HUD saves data when clicked and loads it on scene start.

Event to save HUD values (hitpoints and money), the states of collected objects, and the player's position and rotation by sending a "Saving" message to those variables:

Save Variable Values

Event to load HUD values (hitpoints and money), the states of collected objects, and the player's position and rotation by sending a "Loading" message to those variables:

Load Variable Values

Events to Load/Save data on a collected object variable to save and load its data, and activate or deactivate the collected objects based on the save data value:

Collected Object Events

The delete save button in the HUD removes the save data and resets objects in the scene.

Event to reset the saved data of the hitpoints and money variables in the HUD, the states of collected objects, and the player's position and rotation:

Reset Saved Data

Event to reset the values of hitpoints and money variables in the HUD, the states of collected objects in the scene, and the player's position and rotation:

Reset Values

Event to move the Player to the saved position/rotation on scene start:

Move Player Event

You can use save data for so much more too! Want to save the scene in which a player exited an experience, and load them in that scene when they load again? How about the day/night time value in scene with dynamic daytime enabled? Or offer multiple save states? Just consider the possibilities...