# GooglePlayGames.BasicApi.SavedGame.ISavedGameClient

The main entry point for interacting with saved games.

## Summary

Saved games are persisted in the cloud along with several game-specific properties ([ISavedGameMetadata](https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-metadata#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_metadata) for more information). There are several core concepts involved with saved games:

**Filenames** - act as unique identifiers for saved games. Two devices performing a read or write using the same filename will end up reading or modifying the same file (i.e. filenames are not device specific).

**Saved Game Metadata** are represented by [ISavedGameMetadata](https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-metadata#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_metadata). The instances allow access to metadata properties about the underlying saved game (e.g. description). In addition, metadata functions as a handle that are required to read and manipulate saved game contents. Lastly, metadata may be "Open". Open metadata instances are required to manipulate the underlying binary data of the saved game. See method comments to determine whether a specific method requires or returns an open saved game.

**Conflicts** occur when multiple devices attempt to write to the same file at the same time. The saved game system guarantees that no conflicting writes will be lost or silently overwritten. Instead, they must be handled the next time the file with a conflict is Opened. Conflicts can be handled automatically ( [OpenWithAutomaticConflictResolution](https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-client#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_client_1ae90da5dda5a18768926a3eb70bd17c9f)) or can be manuallyhandled by the developer ([OpenWithManualConflictResolution](https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-client#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_client_1a146de9505138b0a6d88075d202fde51d)). See the Open methods for more discussion.

Saved games will generally be used in the following workflow:


1. Determine which saved game to use (either using a hardcoded filename or ShowSelectSavedGameUI)
2. Open the file using OpenWithManualConflictResolution or OpenWithAutomaticConflictResolution
3. Read the binary data of the saved game using ReadBinaryData handle it as appropriate for your game.
4. When you have updates, persist them in the cloud using CommitUpdate. Note that writing to the cloud is relatively expensive, and shouldn't be done frequently.

<br />

See online [documentation for Saved Games](https://developers.google.com/games/services/common/concepts/savedgames) for more information.

| ### Public functions ||
|---|---|
| `https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-client#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_client_1aea6699bb5022679fc9fd1511bcda0c00(https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-metadata#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_metadata metadata, https://developer.android.com/games/services/unity/v2/api/struct/google-play-games/basic-api/saved-game/saved-game-metadata-update#struct_google_play_games_1_1_basic_api_1_1_saved_game_1_1_saved_game_metadata_update updateForMetadata, byte[] updatedBinaryData, Action< https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api/saved-game#namespace_google_play_games_1_1_basic_api_1_1_saved_game_1a4bbde44ee3348f73449c1432a85637ab, https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-metadata#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_metadata > callback)` | `void` Durably commits an update to the passed saved game. |
| `https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-client#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_client_1a0064f33b0634774707cce7e6710091a1(https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-metadata#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_metadata metadata)` | `void` Delete the specified snapshot. |
| `https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-client#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_client_1a8ab8acb94649fbcf25e7f2b26959a61d(https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api#namespace_google_play_games_1_1_basic_api_1a7b061047c3edf97247d4d1ccd52e2aec source, Action< https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api/saved-game#namespace_google_play_games_1_1_basic_api_1_1_saved_game_1a4bbde44ee3348f73449c1432a85637ab, List< https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-metadata#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_metadata >> callback)` | `void` Returns the metadata for all known saved games for this game. |
| `https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-client#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_client_1ae90da5dda5a18768926a3eb70bd17c9f(string filename, https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api#namespace_google_play_games_1_1_basic_api_1a7b061047c3edf97247d4d1ccd52e2aec source, https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api/saved-game#namespace_google_play_games_1_1_basic_api_1_1_saved_game_1aaa9aaacffc574c503e5c6ed30b9da6e4 resolutionStrategy, Action< https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api/saved-game#namespace_google_play_games_1_1_basic_api_1_1_saved_game_1a4bbde44ee3348f73449c1432a85637ab, https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-metadata#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_metadata > callback)` | `void` Opens the file with the indicated name and data source. |
| `https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-client#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_client_1a146de9505138b0a6d88075d202fde51d(string filename, https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api#namespace_google_play_games_1_1_basic_api_1a7b061047c3edf97247d4d1ccd52e2aec source, bool prefetchDataOnConflict, https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api/saved-game#namespace_google_play_games_1_1_basic_api_1_1_saved_game_1a788cd50d6c6a4d82d3eef9b51fbd246a conflictCallback, Action< https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api/saved-game#namespace_google_play_games_1_1_basic_api_1_1_saved_game_1a4bbde44ee3348f73449c1432a85637ab, https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-metadata#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_metadata > completedCallback)` | `void` Opens the file with the indicated name and data source. |
| `https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-client#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_client_1a0e41a439e181a5924572da76f8475b46(https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-metadata#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_metadata metadata, Action< https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api/saved-game#namespace_google_play_games_1_1_basic_api_1_1_saved_game_1a4bbde44ee3348f73449c1432a85637ab, byte[]> completedCallback)` | `void` Reads the binary data of the passed saved game. |
| `https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-client#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_client_1ab87347fad93b32c12b64cee814e64fc6(string uiTitle, uint maxDisplayedSavedGames, bool showCreateSaveUI, bool showDeleteSaveUI, Action< https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api/saved-game#namespace_google_play_games_1_1_basic_api_1_1_saved_game_1a4e46a22deed238dbb8ad23eb71d5194f, https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-metadata#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_metadata > callback)` | `void` Shows the select saved game UI with the indicated configuration. |

## Public functions

### CommitUpdate

```c#
void CommitUpdate(
  ISavedGameMetadata metadata,
  SavedGameMetadataUpdate updateForMetadata,
  byte[] updatedBinaryData,
  Action< SavedGameRequestStatus, ISavedGameMetadata > callback
)
```
Durably commits an update to the passed saved game.

When this method returns successfully, the data is durably persisted to disk and will eventually be uploaded to the cloud (in practice, this will happen very quickly unless the device does not have a network connection). If an update to the saved game has occurred after the metadata was retrieved from the cloud, this update will produce a conflict (this commonly occurs if two different devices are writing to the cloud at the same time). All conflicts must be handled the next time this saved game is opened. See [OpenWithManualConflictResolution](https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-client#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_client_1a146de9505138b0a6d88075d202fde51d) and [OpenWithAutomaticConflictResolution](https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-client#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_client_1ae90da5dda5a18768926a3eb70bd17c9f) for more information.

<br />

Details Parameters `metadata` The metadata for the saved game to update. This metadata must be Open (i.e. [ISavedGameMetadata.IsOpen](https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-metadata#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_metadata_1ae203925fc56f0eb392727b47ea8d26f5) returns true)."/\> If it is not open, the method will immediately fail with status All updates that should be applied to the saved game metadata. `updatedBinaryData` The new binary content of the saved game `callback` The callback that is invoked when this operation finishes. The returned metadata will only be non-null if the commit succeeded. If an error is encountered during conflict resolution, that error will be reflected here. This callback will always execute on the game thread and the returned metadata (if any) will NOT be "Open" (i.e. commiting an update closes the metadata).

### Delete

```c#
void Delete(
  ISavedGameMetadata metadata
)
```
Delete the specified snapshot.

This will delete the data of the snapshot locally and on the server.

<br />

Details Parameters `metadata` the saved game metadata identifying the data to delete.

### FetchAllSavedGames

```c#
void FetchAllSavedGames(
  DataSource source,
  Action< SavedGameRequestStatus, List< ISavedGameMetadata >> callback
)
```
Returns the metadata for all known saved games for this game.

All returned saved games are not open, and must be opened before they can be used for writes or binary data reads. The callback will always occur on the game thread.

<br />

Details Parameters `source` The data source to use. [DataSource](https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api#namespace_google_play_games_1_1_basic_api_1a7b061047c3edf97247d4d1ccd52e2aec) for a description of the available options here. `callback` The callback that is invoked when this operation finishes. The returned metadata will only be non-empty if the commit succeeded. If an error is encountered during the fetch, that error will be reflected here. This callback will always execute on the game thread and the returned metadata (if any) will NOT be "Open".

### OpenWithAutomaticConflictResolution

```c#
void OpenWithAutomaticConflictResolution(
  string filename,
  DataSource source,
  ConflictResolutionStrategy resolutionStrategy,
  Action< SavedGameRequestStatus, ISavedGameMetadata > callback
)
```
Opens the file with the indicated name and data source.

If the file has an outstanding conflict, it will be resolved using the specified conflict resolution strategy. The metadata returned by this method will be "Open" - it can be used as a parameter for [CommitUpdate](https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-client#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_client_1aea6699bb5022679fc9fd1511bcda0c00) and ResolveConflictByChoosingMetadata.

<br />

Details Parameters `filename` The name of the file to open. Filenames must consist of only non-URL reserved characters (i.e. a-z, A-Z, 0-9, or the symbols "-", ".", "_", or "\~") be between 1 and 100 characters in length (inclusive). `source` The data source to use. [DataSource](https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api#namespace_google_play_games_1_1_basic_api_1a7b061047c3edf97247d4d1ccd52e2aec) for a description of the available options here. `resolutionStrategy` The conflict resolution that should be used if any conflicts are encountered while opening the file. [ConflictResolutionStrategy](https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api/saved-game#namespace_google_play_games_1_1_basic_api_1_1_saved_game_1aaa9aaacffc574c503e5c6ed30b9da6e4) for a description of these strategies. `callback` The callback that is invoked when this operation finishes. The returned metadata will only be non-null if the open succeeded. This callback will always execute on the game thread and the returned metadata (if any) will be "Open".

### OpenWithManualConflictResolution

```c#
void OpenWithManualConflictResolution(
  string filename,
  DataSource source,
  bool prefetchDataOnConflict,
  ConflictCallback conflictCallback,
  Action< SavedGameRequestStatus, ISavedGameMetadata > completedCallback
)
```
Opens the file with the indicated name and data source.

If there is a conflict that requires resolution, it will be resolved manually using the passed conflict callback. Once all pending conflicts are resolved, the completed callback will be invoked with the retrieved data. In the event of an error, the completed callback will be invoked with the corresponding error status. All callbacks will be executed on the game thread.

<br />

Details Parameters `filename` The name of the file to open. Filenames must consist of only non-URL reserved characters (i.e. a-z, A-Z, 0-9, or the symbols "-", ".", "_", or "\~") be between 1 and 100 characters in length (inclusive). `source` The data source to use. [DataSource](https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api#namespace_google_play_games_1_1_basic_api_1a7b061047c3edf97247d4d1ccd52e2aec) for a description of the available options here. `prefetchDataOnConflict` If set to `true`, the data for the two conflicting files will be automatically retrieved and passed as parameters in *conflictCallback* . If set to `false`, `null` binary data will be passed into *conflictCallback* and the caller will have to fetch it themselves. `conflictCallback` The callback that will be invoked if one or more conflict is encountered while executing this method. Note that more than one conflict may be present and that this callback might be executed more than once to resolve multiple conflicts. This callback is always executed on the game thread. `completedCallback` The callback that is invoked when this operation finishes. The returned metadata will only be non-null if the open succeeded. If an error is encountered during conflict resolution, that error will be reflected here. This callback will always execute on the game thread and the returned metadata (if any) will be "Open".

### ReadBinaryData

```c#
void ReadBinaryData(
  ISavedGameMetadata metadata,
  Action< SavedGameRequestStatus, byte[]> completedCallback
)
```
Reads the binary data of the passed saved game.

The passed metadata must be opened (i.e. [ISavedGameMetadata.IsOpen](https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-metadata#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_metadata_1ae203925fc56f0eb392727b47ea8d26f5) returns true). The callback will always be executed on the game thread.

<br />

Details Parameters `metadata` The metadata for the saved game whose binary data we want to read. This metadata must be open. If it is not open, the method will immediately fail with status SelectUIStatus.BadInputError. `completedCallback` The callback that is invoked when the read finishes. If the read completed without error, the passed status will be SavedGameRequestStatus.Success and the passed bytes will correspond to the binary data for the file. In the case of

### ShowSelectSavedGameUI

```c#
void ShowSelectSavedGameUI(
  string uiTitle,
  uint maxDisplayedSavedGames,
  bool showCreateSaveUI,
  bool showDeleteSaveUI,
  Action< SelectUIStatus, ISavedGameMetadata > callback
)
```
Shows the select saved game UI with the indicated configuration.

If the user selects a saved game in that UI, it will be returned in the passed callback. This metadata will be unopened and must be passed to either [OpenWithManualConflictResolution](https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-client#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_client_1a146de9505138b0a6d88075d202fde51d) or [OpenWithAutomaticConflictResolution](https://developer.android.com/games/services/unity/v2/api/interface/google-play-games/basic-api/saved-game/i-saved-game-client#interface_google_play_games_1_1_basic_api_1_1_saved_game_1_1_i_saved_game_client_1ae90da5dda5a18768926a3eb70bd17c9f) in order to retrieve the binary data. The callback will always be executed on the game thread.

<br />

Details Parameters `uiTitle` The user-visible title of the displayed selection UI. `maxDisplayedSavedGames` The maximum number of saved games the UI may display. This value must be greater than 0. `showCreateSaveUI` If set to `true`, show UI that will allow the user to create a new saved game. `showDeleteSaveUI` If set to `true` show UI that will allow the user to delete a saved game. `callback` The callback that is invoked when an error occurs or if the user finishes interacting with the UI. If the user selected a saved game, this will be passed into the callback along with the SelectUIStatus.SavedGameSelected status. This saved game will not be Open, and must be opened before it can be written to or its binary data can be read. If the user backs out of the UI without selecting a saved game, this callback will receive [UserClosedUI](https://developer.android.com/games/services/unity/v2/api/namespace/google-play-games/basic-api/saved-game#namespace_google_play_games_1_1_basic_api_1_1_saved_game_1a4e46a22deed238dbb8ad23eb71d5194fa554bc5ba1345a0471e5a986494e87467) and a null saved game. This callback will always execute on the game thread.