Skip to Content

Data

The Data module provides functionality for storing and retrieving game data in the cloud, with automatic fallback to local storage in the Unity Editor.

Overview

The Data module allows you to:

  • Store integers, floats, and strings in the cloud
  • Retrieve stored data with default value fallbacks
  • Remove specific data entries
  • Clear all stored data
  • Automatic local storage fallback using PlayerPrefs in Editor

In WebGL builds, data is stored in the Pixidus cloud. In the Unity Editor, data is stored locally using PlayerPrefs for testing purposes.

Methods

Integers

SetInt

Store an integer value with a specified key.

// Store an integer value PixidusSDK.Data.SetInt("highScore", 1000, (success) => { if (success) { Debug.Log("High score saved!"); } else { Debug.Log("Failed to save high score"); } });

GetInt

Retrieve an integer value. Returns the default value if the key doesn’t exist.

// Get an integer value with default fallback PixidusSDK.Data.GetInt("highScore", 0, (value) => { Debug.Log($"High score: {value}"); highScoreText.text = value.ToString(); });

Floats

SetFloat

Store a float value with a specified key.

// Store a float value PixidusSDK.Data.SetFloat("musicVolume", 0.75f, (success) => { if (success) { Debug.Log("Volume setting saved!"); } });

GetFloat

Retrieve a float value. Returns the default value if the key doesn’t exist.

// Get a float value with default fallback PixidusSDK.Data.GetFloat("musicVolume", 1.0f, (value) => { Debug.Log($"Music volume: {value}"); audioSource.volume = value; });

Strings

SetString

Store a string value with a specified key.

// Store a string value PixidusSDK.Data.SetString("playerName", "Player1", (success) => { if (success) { Debug.Log("Player name saved!"); } });

GetString

Retrieve a string value. Returns the default value if the key doesn’t exist.

// Get a string value with default fallback PixidusSDK.Data.GetString("playerName", "Guest", (value) => { Debug.Log($"Player name: {value}"); playerNameText.text = value; });

Data Management

RemoveItem

Remove a specific data entry by key.

// Remove a specific item PixidusSDK.Data.RemoveItem("highScore", (success) => { if (success) { Debug.Log("High score data removed"); } });

ClearData

Remove all stored data for the current user.

// Clear all stored data PixidusSDK.Data.ClearData((success) => { if (success) { Debug.Log("All data cleared!"); } });

Use ClearData with caution! This will permanently delete all stored data for the user.


Example Usage

Here’s a complete example of implementing game save/load functionality:

using UnityEngine; using UnityEngine.UI; using TMPro; using Pixidus; public class GameDataManager : MonoBehaviour { public TMP_Text highScoreText; public TMP_Text levelText; public Slider volumeSlider; private int currentScore = 0; private int highScore = 0; private int currentLevel = 1; private void Start() { LoadAllData(); volumeSlider.onValueChanged.AddListener(OnVolumeChanged); } public void LoadAllData() { // Load high score PixidusSDK.Data.GetInt("highScore", 0, (value) => { highScore = value; highScoreText.text = $"High Score: {highScore}"; }); // Load current level PixidusSDK.Data.GetInt("currentLevel", 1, (value) => { currentLevel = value; levelText.text = $"Level: {currentLevel}"; }); // Load volume setting PixidusSDK.Data.GetFloat("musicVolume", 1.0f, (value) => { volumeSlider.value = value; AudioListener.volume = value; }); } public void AddScore(int points) { currentScore += points; if (currentScore > highScore) { highScore = currentScore; highScoreText.text = $"High Score: {highScore}"; // Save new high score PixidusSDK.Data.SetInt("highScore", highScore, (success) => { if (success) Debug.Log("New high score saved!"); }); } } public void CompleteLevel() { currentLevel++; levelText.text = $"Level: {currentLevel}"; // Save progress PixidusSDK.Data.SetInt("currentLevel", currentLevel, (success) => { if (success) Debug.Log($"Progress saved - Level {currentLevel}"); }); } private void OnVolumeChanged(float value) { AudioListener.volume = value; // Save volume setting PixidusSDK.Data.SetFloat("musicVolume", value, null); } public void ResetProgress() { PixidusSDK.Data.ClearData((success) => { if (success) { Debug.Log("All progress reset!"); LoadAllData(); // Reload defaults } }); } }

Support

Need help? Our support team is here for you:

Last updated on