API Reference
Complete reference for all public TinySave APIs, organized by functionality.
SaveManager
Core static API for save/load operations.
Methods
SaveAsync
public static async Task SaveAsync(string slot, CancellationToken ct = default)Asynchronously saves all scene data to a slot.
Parameters:
slot- Save slot name (e.g., “quicksave”, “slot1”, “autosave”)ct- Optional cancellation token
Example:
await SaveManager.SaveAsync("slot1");
// With cancellation
var cts = new CancellationTokenSource();
await SaveManager.SaveAsync("slot1", cts.Token);Performance: Serialization and I/O run on background threads.
SaveSync
public static void SaveSync(string slot)Synchronously saves all scene data to a slot. Use during OnApplicationQuit or other blocking scenarios to avoid deadlocks.
Parameters:
slot- Save slot name
Example:
void OnApplicationQuit()
{
SaveManager.SaveSync("autosave");
}Warning: Blocks the main thread. Use SaveAsync() during gameplay.
LoadAsync
public static async Task<bool> LoadAsync(string slot, CancellationToken ct = default)Asynchronously loads scene data from a slot.
Parameters:
slot- Save slot namect- Optional cancellation token
Returns: true if load succeeded, false if slot doesn’t exist
Example:
bool success = await SaveManager.LoadAsync("slot1");
if (success)
{
Debug.Log("Game loaded");
}
else
{
Debug.Log("No save file found");
}HasSlot
public static bool HasSlot(string slot)Checks if a save slot exists.
Parameters:
slot- Save slot name
Returns: true if save file exists
Example:
if (SaveManager.HasSlot("slot1"))
{
await SaveManager.LoadAsync("slot1");
}
else
{
StartNewGame();
}DeleteSlot
public static void DeleteSlot(string slot)Deletes a save slot file.
Parameters:
slot- Save slot name
Example:
SaveManager.DeleteSlot("slot1");GetSlotPath
public static string GetSlotPath(string slot)Gets the full file system path for a save slot.
Parameters:
slot- Save slot name
Returns: Absolute path to save file
Example:
string path = SaveManager.GetSlotPath("slot1");
Debug.Log($"Save file: {path}");
// Output: "C:/Users/Name/AppData/LocalLow/Company/Game/slot1.tsf"PeekMeta
public static SaveMetadata? PeekMeta(string slot)Reads save file metadata without loading the entire file.
Parameters:
slot- Save slot name
Returns: SaveMetadata if file exists and is valid, null otherwise
Example:
SaveMetadata? meta = SaveManager.PeekMeta("slot1");
if (meta.HasValue)
{
Debug.Log($"Version: {meta.Value.version}");
Debug.Log($"Timestamp: {meta.Value.timestamp}");
Debug.Log($"Scenes: {string.Join(", ", meta.Value.scenes)}");
}Configure
public static void Configure(SaveManagerConfig config)Configures SaveManager with custom settings including encryption and storage paths.
Parameters:
config- Configuration object with encryption and storage settings
Throws:
ArgumentNullException- When config is nullInvalidOperationException- When encryption is enabled but key is missing
Example:
var config = SaveManagerConfig.CreateDefault();
config.EncryptionEnabled = true;
config.EncryptionKey = "my-secure-key";
SaveManager.Configure(config);Important: Call before any save/load operations if using encryption or custom paths.
Properties
LastPerfCounters
public static PerfCounters LastPerfCounters { get; }Gets performance metrics from the last save or load operation.
Example:
await SaveManager.SaveAsync("slot1");
Debug.Log(SaveManager.LastPerfCounters.ToString());
// "Capture=5ms, Serialize=12ms, IO=8ms, Total=25ms, Bytes=52481"Config
public static SaveManagerConfig Config { get; }Gets the current SaveManager configuration.
Example:
SaveManagerConfig config = SaveManager.Config;
Debug.Log($"Encryption: {config.EncryptionEnabled}");
Debug.Log($"Extension: {config.FileExtension}");Events
BeforeSave
public static event Action BeforeSave;Fires before any save operation, before ISaveCallbacks.OnBeforeSave().
Example:
void OnEnable()
{
SaveManager.BeforeSave += OnBeforeSave;
}
void OnDisable()
{
SaveManager.BeforeSave -= OnBeforeSave;
}
void OnBeforeSave()
{
Debug.Log("Game is saving...");
}AfterLoad
public static event Action AfterLoad;Fires after any load operation, after ISaveCallbacks.OnAfterLoad().
Example:
void OnEnable()
{
SaveManager.AfterLoad += OnAfterLoad;
}
void OnDisable()
{
SaveManager.AfterLoad -= OnAfterLoad;
}
void OnAfterLoad()
{
Debug.Log("Game loaded!");
RefreshUI();
}SaveManagerConfig
Configuration for SaveManager behavior including encryption and storage.
Properties
EncryptionEnabled
public bool EncryptionEnabled { get; set; }Enable/disable AES-256 encryption for save files. Default: false
EncryptionKey
public string EncryptionKey { get; set; }Encryption key for AES-256 encryption. Required when EncryptionEnabled is true.
StorageBasePath
public string StorageBasePath { get; set; }Custom base path for save file storage. When null or empty, uses default platform-specific location.
FileExtension
public string FileExtension { get; set; }File extension for save files (without leading dot). Default: "tsf"
Methods
CreateDefault
public static SaveManagerConfig CreateDefault()Creates a SaveManagerConfig with default values.
Returns: New config with encryption disabled and default settings
Example:
var config = SaveManagerConfig.CreateDefault();
config.EncryptionEnabled = true;
config.EncryptionKey = "my-key";
SaveManager.Configure(config);CreateStorage
public IStorage CreateStorage()Creates an IStorage instance based on configuration settings.
Returns: Configured storage instance (encrypted or plain)
Throws: InvalidOperationException if encryption is enabled without a key
TinySaveSettings
Global settings persisted in PlayerPrefs.
Properties
defaultSettings
public static TinySaveSettings defaultSettings { get; }Singleton instance. Settings are automatically loaded from and saved to PlayerPrefs.
Example:
TinySaveSettings.defaultSettings.encryptionEnabled = true;
TinySaveSettings.defaultSettings.encryptionKey = "my-key";encryptionEnabled
public bool encryptionEnabled { get; set; }Enable/disable encryption. Automatically persists to PlayerPrefs.
encryptionKey
public string encryptionKey { get; set; }Encryption key. Automatically persists to PlayerPrefs.
storageBasePath
public string storageBasePath { get; set; }Custom storage path. Automatically persists to PlayerPrefs.
Methods
ToConfig
public SaveManagerConfig ToConfig()Converts TinySaveSettings to SaveManagerConfig.
Returns: SaveManagerConfig with matching settings
Example:
var settings = TinySaveSettings.defaultSettings;
settings.encryptionEnabled = true;
settings.encryptionKey = "my-key";
var config = settings.ToConfig();
SaveManager.Configure(config);ReloadFromPrefs
public static void ReloadFromPrefs()Forces reload of settings from PlayerPrefs, discarding cached instance.
Components
SaveID
Unique identifier component for GameObjects.
Properties
public string ID { get; set; }Unique identifier for this GameObject. Auto-generated as GUID.
Example:
SaveID saveId = GetComponent<SaveID>();
Debug.Log($"This object's ID: {saveId.ID}");TinySaveAutoSave
Component-level configuration for what to save on a GameObject.
Properties
public bool AutoSaveEnabled { get; set; }Enable/disable auto-save for this GameObject.
public bool saveActive { get; set; }Save GameObject.activeSelf state.
public bool saveDestroyed { get; set; }Track if GameObject is destroyed.
public bool saveHideFlags { get; set; }Save GameObject.hideFlags.
public bool saveName { get; set; }Save GameObject.name.
public bool saveTag { get; set; }Save GameObject.tag.
public bool saveLayer { get; set; }Save GameObject.layer.
public List<Component> componentsToSave { get; set; }List of components to save on this GameObject.
Methods
AddComponentToSave
public void AddComponentToSave(Component component)Adds a component to the save list.
Example:
var autoSave = GetComponent<TinySaveAutoSave>();
autoSave.AddComponentToSave(GetComponent<Rigidbody>());RemoveComponentToSave
public void RemoveComponentToSave(Component component)Removes a component from the save list.
IsComponentSelected
public bool IsComponentSelected(Component component)Checks if a component is in the save list.
Returns: true if component is selected for saving
GetSelectedComponents
public ReadOnlyCollection<Component> GetSelectedComponents()Gets all selected components.
Returns: Read-only list of selected components
ClearSelectedComponents
public void ClearSelectedComponents()Removes all components from the save list.
TinySaveManager
Scene-level manager for automatic save/load timing.
Enums
SaveTiming
public enum SaveTiming
{
None, // Manual save only
OnApplicationQuit, // Save when quitting
OnApplicationPause // Save when pausing (mobile)
}LoadTiming
public enum LoadTiming
{
None, // Manual load only
Awake, // Load in Awake()
Start // Load in Start()
}Properties
public SaveTiming whenToSave { get; set; }When to automatically save. Default: OnApplicationQuit
public LoadTiming whenToLoad { get; set; }When to automatically load. Default: Awake
public string saveSlot { get; set; }Save slot name for automatic operations. Default: "autosave"
public static TinySaveManager Instance { get; }Singleton instance for the current scene.
Methods
PerformSaveAsync
public async Task PerformSaveAsync()Manually trigger a save operation.
Example:
await TinySaveManager.Instance.PerformSaveAsync();PerformLoadAsync
public async Task PerformLoadAsync()Manually trigger a load operation.
TinySaveReferenceManager
Manages references to objects without SaveID components.
Methods
GetId
public long GetId(UnityEngine.Object obj)Gets the internal ID for an object.
Parameters:
obj- Object to get ID for
Returns: ID or -1 if not tracked
GetObject
public UnityEngine.Object GetObject(long id)Gets an object by its internal ID.
Parameters:
id- Internal ID
Returns: Object or null if not found
HasReference
public bool HasReference(UnityEngine.Object obj)Checks if an object is tracked.
Returns: true if object is tracked
Add
public long Add(UnityEngine.Object obj)Adds an object to the reference manager.
Parameters:
obj- Object to track
Returns: Assigned ID
Example:
var refManager = FindFirstObjectByType<TinySaveReferenceManager>();
Light light = FindFirstObjectByType<Light>();
long lightId = refManager.Add(light);ClearReferences
public void ClearReferences()Removes all tracked references.
GetReferenceCount
public int GetReferenceCount()Gets the number of tracked references.
Returns: Reference count
Attributes
SaveFieldAttribute
Marks fields and properties for saving.
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class SaveFieldAttribute : Attribute
{
public string KeyOverride { get; }
public SaveFieldAttribute(string keyOverride = null)
}Parameters:
keyOverride- Optional: Override field name for backwards compatibility
Example:
[SaveField]
public int health;
[SaveField("oldPlayerName")] // Support renamed fields
public string playerName;Interfaces
ISaveCallbacks
Receive notifications before save and after load.
public interface ISaveCallbacks
{
void OnBeforeSave();
void OnAfterLoad();
}Example:
public class Player : MonoBehaviour, ISaveCallbacks
{
[SaveField] private Vector3 savedPosition;
public void OnBeforeSave()
{
savedPosition = transform.position;
}
public void OnAfterLoad()
{
transform.position = savedPosition;
}
}ISaveCustom
Full control over serialization.
public interface ISaveCustom
{
object CaptureState();
void RestoreState(object state);
}Example:
public class CustomData : MonoBehaviour, ISaveCustom
{
public object CaptureState()
{
return new Dictionary<string, object>
{
{ "key", "value" }
};
}
public void RestoreState(object state)
{
var dict = state as Dictionary<string, object>;
// Restore data
}
}ISaveMigration
Migrate save files between format versions.
public interface ISaveMigration
{
int FromVersion { get; }
int ToVersion { get; }
bool TryMigrate(ref SaveFile file);
}Example:
public class Migration_1_to_2 : ISaveMigration
{
public int FromVersion => 1;
public int ToVersion => 2;
public bool TryMigrate(ref SaveFile file)
{
// Transform old data to new format
return true;
}
}Data Models
SaveFile
Root structure for save file data.
public struct SaveFile
{
public SaveMetadata meta;
public List<EntityRecord> entities;
public List<AssetRecord> assets;
}SaveMetadata
Metadata about a save file.
public struct SaveMetadata
{
public string version; // Game version
public long timestamp; // Unix timestamp
public string build; // Build identifier
public List<string> scenes; // Scene names
public bool compressed; // Is compressed
public int formatVersion; // Save format version
}EntityRecord
Save data for a GameObject.
public struct EntityRecord
{
public string id; // SaveID
public string scene; // Scene name
public string prefab; // Prefab path
public bool active; // GameObject.activeSelf
public string name; // GameObject.name
public string tag; // GameObject.tag
public int layer; // GameObject.layer
public HideFlags hideFlags; // GameObject.hideFlags
public List<ComponentRecord> components;
}ComponentRecord
Save data for a Component.
public struct ComponentRecord
{
public string type; // Component type name
public Dictionary<string, object> fields; // Field data
}AssetRecord
Save data for a ScriptableObject.
public struct AssetRecord
{
public string guid; // Asset GUID
public string type; // Asset type name
public Dictionary<string, object> fields; // Field data
}Performance Monitoring
PerfCounters
Performance metrics for save/load operations.
public class PerfCounters
{
public long CaptureMs { get; }
public long SerializeMs { get; }
public long IoMs { get; }
public long ResolveMs { get; }
public long TotalMs { get; }
public long BytesWritten { get; }
}Example:
await SaveManager.SaveAsync("slot1");
PerfCounters perf = SaveManager.LastPerfCounters;
Debug.Log($"Capture: {perf.CaptureMs}ms");
Debug.Log($"Serialize: {perf.SerializeMs}ms");
Debug.Log($"IO: {perf.IoMs}ms");
Debug.Log($"Total: {perf.TotalMs}ms");
Debug.Log($"Size: {perf.BytesWritten} bytes");Storage & Encryption
IStorage
Interface for file storage operations.
public interface IStorage
{
Task WriteTextAtomicAsync(string path, string content, CancellationToken ct = default);
void WriteTextAtomic(string path, string content);
Task<string> ReadTextAsync(string path, CancellationToken ct = default);
string ReadText(string path);
bool Exists(string path);
void Delete(string path);
string GetFullPath(string relativePath);
}IEncryption
Interface for encryption/decryption operations.
public interface IEncryption
{
string Encrypt(string plaintext);
string Decrypt(string ciphertext);
}SaveDatabase
Migration management and format versioning.
Constants
public const int CurrentFormatVersion = 1;Current save file format version.
Methods
Migrate
public static SaveFile Migrate(SaveFile file)Applies migrations to bring a save file up to the current format version.
Parameters:
file- Save file to migrate
Returns: Migrated save file
Note: Called automatically during LoadAsync().