Save + Load State

The State API saves and loads the state of a player's gameplay, allowing a player to continue from the last saved state. This is a separate concept from Player Progress, which is a progress indicator that is displayed to the instructor.

Your game has a single state value, which is overwritten each time you save state. In Unity, this can be any data of your choice, and the API will handle all serialization/deserialization. In Javascript, this can be any string data (e.g. JSON.stringify). Be sure to include your entire state payload each time you save state.

Your game's init scene must support buttons for New Game and Continue. The Unity SDK includes a Helper class (LegendsOfLearning-Example > Scripts > Helper.cs) to manage these buttons and state initialization. Unity developers can use this Helper class or implement your own flow. Javascript developers must implement the flow as follows:

  1. As soon as your game is initialized, you must call load state to check for any saved state.

  2. If valid state is available, then both New Game and Continue buttons should be visible.

  3. Clicking Continue will resume the player with the saved state, and also report the last saved Progress increment back to the server.

  4. Clicking New Game will start the player with default state.

While your game is required to support saving state, there is not a specific minimum requirement for save frequency. In general, we recommend that players should not lose more than 3 minutes of playtime when they exit and resume the game. If your game has sequential levels, then you should save state at the start of each level. If your game includes one or more tutorials, then you should save state before each tutorial so the player has the opportunity to review the tutorial when they resume.

When a player continues from loaded state, your game should resume Player Progress at the increment that corresponds to the saved state. The Unity API automatically saves and returns the most recently reported Progress increment (and optional score) with the state during SaveState and LoadState. Javascript developers should include Progress in their own state payload and also relay it back to the server after loading state.

If the Unity API detects that there is no player session available on the server (for example in a game preview or anonymous mode) then the state will be saved locally on the browser/device using PlayerPrefs.

Migrating saved state to a new game version is not supported at this time. If you submit a new version of your game and it is accepted and published to the LOL server, then any saved player state for the previous game version will be invalidated.

Unity developers can reference the LegendsOfLearning-Example project included in the SDK for a fully functioning example of Save + Load State. This example will be folded into the main Example Project in the next SDK version.

‚Äč