Playgama
  • Welcome
  • 🚀Quick start
  • Submitting a game
  • Game Requirments
    • 💥Self-check
    • Technical Requirements
    • Advertising Requirements
    • User Experience Requirements
    • Content Requirements
    • Other Requirements
    • Platform-Specific Requirements
  • In-Game Purchases
    • Step-by-step IAP integration guide for Unity
  • FAQ
    • General
    • Submitting a Game
    • Game Moderation
    • Payments and Statistics
  • SDK
    • Getting started
    • Engines
      • Core (Plain JS)
        • 💥Intro
        • Setup
        • Platform Parameters
        • User Data
        • Advertising
          • Banner
          • Interstitial
          • Rewarded
          • AdBlock
        • User Parameters
        • Social Interactions
        • Leaderboards
        • Achievements
        • In-Game Purchases
        • Remote Configuration
      • Unity
        • 💥Intro
        • Setup
        • Platform Parameters
        • User Data
        • Advertising
          • Banner
          • Interstitial
          • Rewarded
          • AdBlock
        • User Parameters
        • Social Interactions
        • Leaderboards
        • Achievements
        • In-Game Purchases
        • Remote Configuration
      • Construct 3
        • 💥Intro
        • Setup
        • Platform Parameters
        • User Data
        • Advertising
          • Banner
          • Interstitial
          • Rewarded
          • AdBlock
        • User Parameters
        • Social Interactions
        • Leaderboards
        • Achievements
        • In-Game Purchases
        • Remote Configuration
      • GDevelop
        • 💥Intro
        • Setup
        • Platform Parameters
        • User Data
        • Advertising
          • Banner
          • Interstitial
          • Rewarded
          • AdBlock
        • User Parameters
        • Social Interactions
        • Leaderboards
        • Achievements
        • In-Game Purchases
        • Remote Configuration
      • Godot
        • 💥Intro
        • Setup
        • Platform Parameters
        • User Data
        • Advertising
          • Banner
          • Interstitial
          • Rewarded
          • AdBlock
        • User Parameters
        • Social Interactions
        • Leaderboards
        • Achievements
        • In-Game Purchases
        • Remote Configuration
      • Game Maker
        • 💥Intro
        • Setup
        • Platform Parameters
        • User Data
        • Advertising
          • Banner
          • Interstitial
          • Rewarded
          • AdBlock
        • User Parameters
        • Social Interactions
        • Leaderboards
        • Achievements
        • In-Game Purchases
        • Remote Configuration
      • Defold
        • 💥Intro
        • Setup
        • Platform Parameters
        • User Data
        • Advertising
          • Banner
          • Interstitial
          • Rewarded
          • AdBlock
        • User Parameters
        • Social Interactions
        • Leaderboards
        • Achievements
        • In-Game Purchases
        • Remote Configuration
    • Playgama Bridge Config
    • Changelog
  • For Partners
    • Getting Started
    • Embed the Widget
      • Adding Games Widget to Your WordPress Site
      • Adding Games Widget to Your Tilda Site
      • Adding Games Widget to Your Framer Site
    • Import the Game Catalog
    • Share your referral link
Powered by GitBook
On this page
  1. SDK
  2. Engines
  3. Unity

User Data

PreviousPlatform ParametersNextAdvertising

Last updated 3 months ago

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.

If you need to call storage methods in a sequence, make sure you wait for previous call to finish, so there is no potential data collisions.

Use List<string> parameters for batch operations

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.

Bridge.storage.IsSupported(StorageType.LocalStorage)
Bridge.storage.IsSupported(StorageType.PlatformInternal)

Availability Check

Check if the specified storage type is currently available for use to manage data storage effectively.

Bridge.storage.IsAvailable(StorageType.LocalStorage)
Bridge.storage.IsAvailable(StorageType.PlatformInternal)

Load Data

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 key
private void Start()
{
    Bridge.storage.Get("level", OnStorageGetCompleted);
}

private void OnStorageGetCompleted(bool success, string data)
{
    // Loading succeeded
    if (success)
    {
        if (data != null)
        {
            Debug.Log(data);
        }
        else
        {
            // No data for the key 'level'
        }
    }
    else
    {
        // Error, something went wrong
    }
}

// Get data by multiple keys
private void Start()
{
    Bridge.storage.Get(new List<string>() { "level", "coins" }, OnStorageGetCompleted);
}

private void OnStorageGetCompleted(bool success, List<string> data)
{
    // Loading succeeded
    if (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 type
private void Start()
{
    Bridge.storage.Get("level", OnStorageGetCompleted, StorageType.LocalStorage);
}

private void OnStorageGetCompleted(bool success, string data)
{
    // Loading succeeded
    if (success)
    {
        if (data != null)
        {
            Debug.Log(data);
        }
        else
        {
            // No data for the key 'level'
        }
    }
    else
    {
        // Error, something went wrong
    }
}

Save data to the specified storage with a key to retain player progress or settings.

// Save data by key
private void Start()
{
    Bridge.storage.Set("level", "dungeon_123", OnStorageSetCompleted);
}

private void OnStorageSetCompleted(bool success)
{
    Debug.Log($"OnStorageSetCompleted, success: {success}");
}

// Save data by multiple keys
private void Start()
{
    var keys = new List<string>() { "level", "is_tutorial_completed", "coins" };
    var data = new List<object>() { "dungeon_123", true, 12 };
    Bridge.storage.Set(keys, data, OnStorageSetCompleted);
}

// Save data to a specific storage type
private void Start()
{
    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 key
private void Start()
{
    Bridge.storage.Delete("level", OnStorageDeleteCompleted);
}

private void OnStorageDeleteCompleted(bool success)
{
    Debug.Log($"OnStorageDeleteCompleted, success: {success}");
}

// Delete data by multiple keys
private void Start()
{
    var keys = new List<string>() { "level", "is_tutorial_completed", "coins" };
    Bridge.storage.Delete(keys, OnStorageDeleteCompleted);
}

// Delete data from a specific storage type
private void Start()
{
    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.

Save Data