Components
TinySave provides several MonoBehaviour components that integrate seamlessly with Unity’s workflow. These components handle object identification, component selection, and automatic save/load timing.
SaveID
Required for any GameObject you want to save.
SaveID provides a unique identifier for GameObjects, enabling TinySave to match saved data with scene objects across save/load operations.
Adding SaveID
Add via the Inspector:
- Select your GameObject
- Add Component → TinySave → SaveID
- A unique ID is automatically generated
Add via code:
GameObject player = GameObject.Find("Player");
player.AddComponent<SaveID>();Properties
public class SaveID : MonoBehaviour
{
public string ID { get; set; }
}The ID is automatically generated as a GUID and serialized with your scene. Don’t modify it unless you know what you’re doing.
Important Notes
- One per GameObject - SaveID is marked with
[DisallowMultipleComponent] - Scene persistence - IDs are saved with your scene file
- Unique requirement - Duplicate IDs will cause save/load issues
- Required for references - GameObjects need SaveID to be referenced by other saved objects
Validation
Use the TinySave validation window to check for duplicate or missing SaveIDs:
- Window → TinySave → Validate Scene
TinySaveAutoSave
Marks which components on a GameObject should be saved.
While [SaveField] marks individual fields, TinySaveAutoSave provides component-level control and GameObject property saving.
Basic Setup
// Add via Inspector
// Add Component → TinySave → Auto Save
// The SaveID component is automatically added if not presentGameObject Properties
TinySaveAutoSave can save various GameObject properties:
public class TinySaveAutoSave : MonoBehaviour
{
public bool saveActive; // GameObject.activeSelf
public bool saveDestroyed; // Track if object is destroyed
public bool saveHideFlags; // GameObject.hideFlags
public bool saveName; // GameObject.name
public bool saveTag; // GameObject.tag
public bool saveLayer; // GameObject.layer
public List<Component> componentsToSave; // Which components to save
}Example Usage
// Get the TinySaveAutoSave component
var autoSave = GetComponent<TinySaveAutoSave>();
// Enable saving GameObject properties
autoSave.saveActive = true; // Save active/inactive state
autoSave.saveName = true; // Save GameObject name
autoSave.saveTag = true; // Save tag
// Manually add components to save list
var rigidbody = GetComponent<Rigidbody>();
autoSave.AddComponentToSave(rigidbody);
// Check if a component is selected
bool isSelected = autoSave.IsComponentSelected(rigidbody);
// Remove a component from save list
autoSave.RemoveComponentToSave(rigidbody);
// Get all selected components
var components = autoSave.GetSelectedComponents();
foreach (var component in components)
{
Debug.Log($"Will save: {component.GetType().Name}");
}
// Clear all selected components
autoSave.ClearSelectedComponents();Enable/Disable Auto-Save
var autoSave = GetComponent<TinySaveAutoSave>();
// Temporarily disable auto-save for this GameObject
autoSave.AutoSaveEnabled = false;
// Re-enable it
autoSave.AutoSaveEnabled = true;Editor Workflow
In the Inspector, TinySaveAutoSave shows:
- Checkboxes for GameObject properties (active, destroyed, name, tag, layer, hideFlags)
- Component selector to choose which components to save
- Status indicator showing if auto-save is enabled
TinySaveManager
Scene-level manager that controls when saves and loads occur.
TinySaveManager automates save/load timing based on Unity lifecycle events. Add one per scene to configure automatic behavior.
Save Timing Options
public enum SaveTiming
{
None, // Manual only
OnApplicationQuit, // Save when quitting (desktop)
OnApplicationPause // Save when pausing (mobile)
}Load Timing Options
public enum LoadTiming
{
None, // Manual only
Awake, // Load in Awake()
Start // Load in Start()
}Configuration
public class TinySaveManager : MonoBehaviour
{
public SaveTiming whenToSave = SaveTiming.OnApplicationQuit;
public LoadTiming whenToLoad = LoadTiming.Awake;
public string saveSlot = "autosave";
}Example Setup
// Configure in Inspector or via code
var manager = FindFirstObjectByType<TinySaveManager>();
manager.whenToSave = TinySaveManager.SaveTiming.OnApplicationQuit;
manager.whenToLoad = TinySaveManager.LoadTiming.Start;
manager.saveSlot = "autosave";Manual Save/Load
You can trigger saves and loads manually even with automatic timing configured:
var manager = TinySaveManager.Instance;
// Manual save
await manager.PerformSaveAsync();
// Manual load
await manager.PerformLoadAsync();Singleton Access
// Access the scene's TinySaveManager instance
TinySaveManager manager = TinySaveManager.Instance;Platform-Specific Behavior
TinySaveManager handles platform differences automatically:
// On mobile platforms:
// - OnApplicationQuit is unreliable
// - OnApplicationPause is used as fallback
// - Synchronous save is used to guarantee completion
// On desktop:
// - OnApplicationQuit works reliably
// - Synchronous save ensures data is written before exitImportant Notes
- Uses SaveSync on quit - Prevents deadlocks during Unity shutdown
- Mobile fallback - Automatically saves on pause for mobile platforms
- Cancellation - Operations are cancelled when the manager is destroyed
- Singleton per scene - Only one TinySaveManager per scene is active
TinySaveReferenceManager
Manages references to scene objects that don’t have SaveID components.
Sometimes you need to save references to objects that don’t have SaveIDs (particles, lights, cameras, etc.). TinySaveReferenceManager tracks these objects and assigns them internal IDs.
How It Works
TinySaveReferenceManager maintains a mapping between Unity Objects and long IDs:
public class TinySaveReferenceManager : MonoBehaviour
{
[Serializable]
public class ReferenceEntry
{
public UnityEngine.Object obj;
public long id;
}
}Adding References
var refManager = GetComponent<TinySaveReferenceManager>();
// Add a reference to a Light component
Light sceneLight = FindFirstObjectByType<Light>();
long lightId = refManager.Add(sceneLight);
// Add a Camera reference
Camera mainCam = Camera.main;
long camId = refManager.Add(mainCam);Retrieving References
// Get the ID for an object
long id = refManager.GetId(sceneLight);
// Get an object by ID
UnityEngine.Object obj = refManager.GetObject(id);
Light light = obj as Light;
// Check if an object is tracked
bool isTracked = refManager.HasReference(sceneLight);Managing References
// Get the count of tracked references
int count = refManager.GetReferenceCount();
// Clear all references (use with caution)
refManager.ClearReferences();When to Use
Use TinySaveReferenceManager when:
- You need to save references to objects without SaveID
- The referenced objects are scene-based (not dynamically spawned)
- You want to keep your scene clean by not adding SaveID to everything
Don’t use it for:
- GameObjects you control (use SaveID instead)
- Prefabs you’ll instantiate at runtime
- Asset references (those work automatically)
Example: Saving a Light Reference
using UnityEngine;
using TinySave.Runtime;
public class LightController : MonoBehaviour
{
[SaveField]
private long savedLightId; // Save the ID, not the Light directly
private Light targetLight;
private TinySaveReferenceManager refManager;
void Start()
{
refManager = FindFirstObjectByType<TinySaveReferenceManager>();
targetLight = FindFirstObjectByType<Light>();
// Register the light if not already registered
if (!refManager.HasReference(targetLight))
{
savedLightId = refManager.Add(targetLight);
}
}
public void OnAfterLoad()
{
// Restore the light reference from the saved ID
UnityEngine.Object obj = refManager.GetObject(savedLightId);
targetLight = obj as Light;
}
}Editor Support
In editor mode, TinySaveReferenceManager provides additional methods:
#if UNITY_EDITOR
// Add multiple references at once
List<UnityEngine.Object> objects = new List<UnityEngine.Object> { light1, light2, camera1 };
refManager.AddReferences(objects);
// Get all tracked references
List<TinySaveReferenceManager.ReferenceEntry> allRefs = refManager.GetAllReferences();
#endifComponent Combination Patterns
Pattern 1: Basic Saveable GameObject
GameObject player = new GameObject("Player");
player.AddComponent<SaveID>();
player.AddComponent<PlayerStats>(); // Has [SaveField] attributesPattern 2: Selective Component Saving
GameObject enemy = new GameObject("Enemy");
enemy.AddComponent<SaveID>();
var autoSave = enemy.AddComponent<TinySaveAutoSave>();
autoSave.saveActive = true;
autoSave.saveTag = true;
// Only save specific components
autoSave.AddComponentToSave(enemy.GetComponent<EnemyAI>());
autoSave.AddComponentToSave(enemy.GetComponent<Health>());Pattern 3: Scene Manager with Auto Save/Load
GameObject manager = new GameObject("SaveManager");
var tinySaveManager = manager.AddComponent<TinySaveManager>();
tinySaveManager.whenToSave = TinySaveManager.SaveTiming.OnApplicationQuit;
tinySaveManager.whenToLoad = TinySaveManager.LoadTiming.Awake;
tinySaveManager.saveSlot = "scene_checkpoint";Pattern 4: Reference Manager for Non-SaveID Objects
GameObject refManagerObj = new GameObject("ReferenceManager");
var refManager = refManagerObj.AddComponent<TinySaveReferenceManager>();
// Register scene objects that don't need SaveID
refManager.Add(Camera.main);
refManager.Add(FindFirstObjectByType<Light>());