03. Quick Start ( Advanced API for Developers )

This approach is designed for experienced developers who want full programmatic control over saving and loading.

⚠️ Usually, you don’t need this, adding Saveable components handles everything for you automatically. Use this method only if you want to bypass components entirely, or if you need custom save logic.

Below is a simple example showing how to save data directly in code, without attaching any components to your GameObjects.

Save & Load Without Components(Advanced)

using cowsins.OmniSave;
using cowsins.OmniSave.API;

public class CodeFirstExample : MonoBehaviour
{
    void Start()
    {
        // Save data to memory
        SaveManager.Save("playerHealth", 100, PersistenceScope.Global);
        SaveManager.Save("playerCoins", 250, PersistenceScope.Global);
        SaveManager.Save("doorOpen", true, PersistenceScope.Scene);
        
        // IMPORTANT: Persist to disk!
        SaveManager.SaveAll();
    }
    
    void LoadGame()
    {
        // Load with defaults
        int health = SaveManager.Load("playerHealth", PersistenceScope.Global, 100);
        int coins = SaveManager.Load("playerCoins", PersistenceScope.Global, 0);
        bool isDoorOpen = SaveManager.Load("doorOpen", PersistenceScope.Scene, false);
    }
}
triangle-exclamation

OmniSave uses a two-phase save:

  1. Save() → Writes to RAM (instant, temporary)

  2. SaveAll() → Writes to disk (persistent)

Last updated