Store and manage player data to enhance gameplay experience and retain progress.
There are two types of storage: local (LocalStorage) and internal (PlatformInternal). When writing to local storage, data is saved on the player's device. When writing to internal storage, data is saved on the platform's servers.
Default Storage Type
Identify the default storage type to understand where data is being saved (local or server).
Bridge.storage.defaultType
Used automatically if no specific storage type is specified when working with data. Possible values: LocalStorage, PlatformInternal.
Support Check
Verify if the specified storage type is supported on the platform to ensure compatibility.
Retrieve stored data based on a key or multiple keys to restore player progress or settings.
Don't call SDK methods that require a callback (like Bridge.storage.Get) when starting the game in Awake. Call them in Start.
// Get data by keyprivatevoidStart(){Bridge.storage.Get("level", OnStorageGetCompleted);}privatevoidOnStorageGetCompleted(bool success,string data){ // Loading succeededif (success) {if (data !=null) {Debug.Log(data); }else { // No data for the key 'level' } }else { // Error, something went wrong }}// Get data by multiple keysprivatevoidStart(){Bridge.storage.Get(newList<string>() { "level","coins" }, OnStorageGetCompleted);}privatevoidOnStorageGetCompleted(bool success,List<string> data){ // Loading succeededif (success) {if (data[0] !=null) {Debug.Log($"Level: {data[0]}"); }else { // No data for the key 'level' }if (data[1] !=null) {Debug.Log($"Coins: {data[1]}"); }else { // No data for the key 'coins' } }else { // Error, something went wrong }}// Get data from a specific storage typeprivatevoidStart(){Bridge.storage.Get("level", OnStorageGetCompleted,StorageType.LocalStorage);}privatevoidOnStorageGetCompleted(bool success,string data){ // Loading succeededif (success) {if (data !=null) {Debug.Log(data); }else { // No data for the key 'level' } }else { // Error, something went wrong }}
Save Data
Save data to the specified storage with a key to retain player progress or settings.
// Save data by keyprivatevoidStart(){Bridge.storage.Set("level","dungeon_123", OnStorageSetCompleted);}privatevoidOnStorageSetCompleted(bool success){Debug.Log($"OnStorageSetCompleted, success: {success}");}// Save data by multiple keysprivatevoidStart(){var keys =newList<string>() { "level","is_tutorial_completed","coins" };var data =newList<object>() { "dungeon_123",true,12 };Bridge.storage.Set(keys, data, OnStorageSetCompleted);}// Save data to a specific storage typeprivatevoidStart(){Bridge.storage.Set("level","dungeon_123", OnStorageSetCompleted,StorageType.LocalStorage);}
Delete Data
Remove data from the specified storage by key to manage player data and settings effectively.
// Delete data by keyprivatevoidStart(){Bridge.storage.Delete("level", OnStorageDeleteCompleted);}privatevoidOnStorageDeleteCompleted(bool success){Debug.Log($"OnStorageDeleteCompleted, success: {success}");}// Delete data by multiple keysprivatevoidStart(){var keys =newList<string>() { "level","is_tutorial_completed","coins" };Bridge.storage.Delete(keys, OnStorageDeleteCompleted);}// Delete data from a specific storage typeprivatevoidStart(){Bridge.storage.Delete("level", OnStorageDeleteCompleted,StorageType.LocalStorage);}
If no specific storage type is passed as the third argument when working with data, the default storage type Bridge.storage.defaultType is used.