• Manual
  • API Documentation
  • Guides
  • Basic Saving and Loading

    Show / Hide Table of Contents
    • Introduction
    • Installation
    • Getting Started
    • Demos
    • The Save System API
    • Auto Save
    • Platforms
    • Security
    • Serialization
    • Supported Data Types
    • Migration
    • FAQ
    • Changelog
    • Extend
      • Overview
      • Converter
      • Encryption
      • Storage
    • Guides
      • Overview
      • Configuring Settings
      • Using Auto Save
      • Basic Saving and Loading
      • Saving and Loading Raw Data
      • Deleting the Data
      • Saving and Loading Images
      • Saving and Loading Scene Objects
      • Saving and Loading Assets
      • Saving and Loading Readonly Properties
    • Integrations
      • Overview
      • Google Play Games
      • Xbox Live
      • Bolt
      • Firebase
      • PlayFab
      • PlayMaker
      • Steam Auto-Cloud
      • Steamworks .NET
      • Facepunch Steamworks
      • Text Mesh Pro
    • Storage
      • Overview
      • Backup
      • Catalog
      • Meta Data
      • Built-in Storages
        • File
        • PlayerPrefs
        • Memory
      • Third-party Storages
        • Firebase
          • Realtime Database
          • Cloud Storage
          • Firestore
        • PlayFab
          • Entity Objects
          • Entity Files
          • User Data
        • Steam
          • Steamworks .NET
          • Facepunch Steamworks
        • Google Play
          • Saved Game
        • Xbox Live
          • Connected Storage

    Basic Saving and Loading

    Here we will save a few simple data types using the SaveSystemAPI class as a demonstration of the API usage.

    Saving a Primitive

    async void Start() {
    
        // The location in the storage that we want to save the data, it can be a file, a key, or any kind of identification for the type of storage
        string identifier = "name.json";
    
        // The simple data we're going to save
        string data = "Bayat - Save System";
    
        // Save the data associated with the identifier
        await SaveSystemAPI.SaveAsync(identifier, data);
    
        // Check whether the data exists or not before loading it, or you can provide a default value for the LoadAsync method so it would return the default value if the data does not exists.
        if (await SaveSystemAPI.ExistsAsync(identifier)) {
    
            // Load back the saved data associated with the identifier
            string loadedData = await SaveSystemAPI.LoadAsync<string>(identifier);
        }
    
        Debug.Log(data); // Outputs "Bayat - Save System"
        Debug.Log(loadedData); // Outputs "Bayat - Save System"
    }
    

    Saving a Custom Class

    public class Player {
    
        public string name;
        public int currentHealth;
        public int score;
        public int highScore;
        public Weapon[] weapons;
        
    }
    
    public class Weapon {
    
        public string name;
        public int damage;
    
    }
    
    public class Gun : Weapon {
    
        public int currentAmmo;
    
    }
    
    async void Start() {
    
        // The location in the storage that we want to save the data, it can be a file, a key, or any kind of identification for the type of storage
        string identifier = "name.json";
    
        // The simple data we're going to save
        Player data = new Player();
        data.name = "Michael";
        data.currentHealth = 32;
        data.score = 1000;
        data.highScore = 12000;
        data.weapons = new Weapon[] {
            new Weapon() {
                name = "Knife",
                damage = 1
            },
            new Gun() {
                name = "Pistol",
                damage = 10,
                currentAmmo = 100
            }
        };
    
        // Save the data associated with the identifier
        await SaveSystemAPI.SaveAsync(identifier, data);
    
        // Check whether the data exists or not before loading it, or you can provide a default value for the LoadAsync method so it would return the default value if the data does not exists.
        if (await SaveSystemAPI.ExistsAsync(identifier)) {
    
            // Load back the saved data associated with the identifier
            Player loadedData = await SaveSystemAPI.LoadAsync<Player>(identifier);
        }
    
        Debug.Log(data.name); // Outputs "Michael"
        Debug.Log(loadedData.name); // Outputs "Michael"
        Debug.Log(loadedData.weapons[1] is Gun); // Outputs "True"
    }
    
    • Improve this Doc
    • 0 Comments
    In This Article
    • Saving a Primitive
    • Saving a Custom Class