assembly-definitions
Assembly definition management — when to create asmdefs, reference rules, Editor/Runtime/Test separation, platform filters, compilation speed optimization.
Save/load patterns — ISaveable interface, JSON serialization, save file management, scene persistence, cloud sync prep. Load when implementing save functionality.
$ npx -y skills add XeldarAlz/everything-claude-unity --skill save-system --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/save-systemContext preview
The summary Claude sees to decide when to auto-load this skill.
Save/load patterns — ISaveable interface, JSON serialization, save file management, scene persistence, cloud sync prep. Load when implementing save functionality.
name: save-system description: "Save/load patterns — ISaveable interface, JSON serialization, save file management, scene persistence, cloud sync prep. Load when implementing save functionality." globs: ["**/Save*.cs", "**/Load*.cs", "**/Persist*.cs", "**/Serializ*.cs"]
Patterns for persisting game state to disk: an ISaveable interface for components that need persistence, a central SaveManager that orchestrates capture and restore, JSON serialization, save slot management, and preparation for cloud sync.
Every component that needs to save state implements this interface. The SaveManager discovers all ISaveable objects in the scene and calls them during save/load.
/// <summary>
/// Implement on any MonoBehaviour that needs to persist state across saves.
/// </summary>
public interface ISaveable
{
/// <summary>
/// Unique key for this saveable. Must be stable across sessions.
/// Recommended format: "{scene}_{gameobject}_{component}" or a GUID.
/// </summary>
string SaveKey { get; }
/// <summary>
/// Capture current state as a serializable object.
/// Return a plain C# class or struct (no MonoBehaviour, no ScriptableObject).
/// </summary>
object CaptureState();
/// <summary>
/// Restore state from a previously captured object.
/// Cast the object to the expected type.
/// </summary>
void RestoreState(object state);
}using UnityEngine;
public class Health : MonoBehaviour, ISaveable
{
[SerializeField] private int maxHealth = 100;
[SerializeField] private string saveKey;
private int _currentHealth;
public string SaveKey => saveKey;
private void Awake()
{
_currentHealth = maxHealth;
}
[System.Serializable]
private struct HealthSaveData
{
public int currentHealth;
public int maxHealth;
}
public object CaptureState()
{
return new HealthSaveData
{
currentHealth = _currentHealth,
maxHealth = maxHealth
};
}
public void RestoreState(object state)
{
if (state is HealthSaveData data)
{
_currentHealth = data.currentHealth;
maxHealth = data.maxHealth;
}
}
}The save key must be the same every time the game runs. Options:
1. **Manual string** (simplest): Assign in Inspector. Works for unique objects like "player_health". 2. **GUID component:** Add a `SaveableEntity` MonoBehaviour with a `[SerializeField] private string uniqueId` that generates a GUID in `Reset()` (called when the component is first added in the editor). This auto-generates stable IDs.
using UnityEngine;
public class SaveableEntity : MonoBehaviour
{
[SerializeField] private string uniqueId;
public string UniqueId => uniqueId;
// Called in editor when component is first added
private void Reset()
{
uniqueId = System.Guid.NewGuid().ToString();
}
}---
A single save file contains all captured state, plus metadata.
using System;
using System.Collections.Generic;
[Serializable]
public class SaveData
{
public int saveVersion = 1;
public string timestamp;
public string sceneName;
public float playTime;
// All saveable state, keyed by ISaveable.SaveKey
// Values are JSON strings (serialized individually per saveable)
public Dictionary<string, string> stateEntries = new();
}Using `Dictionary<string, string>` where values are JSON strings (rather than `Dictionary<string, object>`) avoids polymorphic serialization issues with `JsonUtility`. Each ISaveable's state is serialized independently.
---
The central orchestrator. Finds all ISaveable components, serializes their state, and writes to disk.
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SaveManager : MonoBehaviour
{
public static SaveManager Instance { get; private set; }
[SerializeField] private int maxSaveSlots = 3;
private float _sessionStartTime;
public event Action OnSaveCompleted;
public event Action OnLoadCompleted;
private void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(gameObject);
return;
}
Instance = this;
DontDestroyOnLoad(gameObject);
_sessionStartTime = Time.time;
}
// --- File Paths ---
private string GetSaveFolderPath()
{
return Path.Combine(Application.persistentDataPath, "Saves");
}
private string GetSaveFilePath(int slot)
{
return Path.Combine(GetSaveFolderPath(), $"Save{slot}.json");
}
private string GetAutoSaveFilePath()
{
return Path.Combine(GetSaveFolderPath(), "AutoSave.json");
}
// --- Save ---
public void Save(int slot)
{
SaveToFile(GetSaveFilePath(slot));
}
public void AutoSave()
{
SaveToFile(GetAutoSaveFilePath());
}
private void SaveToFile(string path)
{
var saveData = new SaveData
{
saveVersion = 1,
timestamp = DateTime.Now.ToString("o"),
sceneName = SceneManager.GetActiveScene().name,
playTime = Time.time - _sessionStartTime
};
// Find all saveables in the scene
var saveables = FindAllSaveables();
foreach (var saveable in saveables)
{
try
{
object state = saveable.CaptureState();
string json = JsonUtility.ToJson(state);
saveData.stateEntries[saveable.SaveKey] = json;
}
catch (Exception e)
{
Debug.LogError($"Failed to capture state for {saveable.SaThe ultimate Claude Code toolkit for Unity game development. A production-ready, plug-and-play system that gives Claude Code deep Unity expertise — from writing performant C# to building scenes, profiling performance, and triggering iOS/Android builds — all
Assembly definition management — when to create asmdefs, reference rules, Editor/Runtime/Test separation, platform filters, compilation speed optimization.
Structured commit trailers — adds Constraint, Rejected, Scope-risk, and Not-tested metadata to commit messages. Captures architectural decisions and known gaps…
Ambiguity gating — detects vague feature requests and forces structured requirements gathering with scoring across scope, platform, performance, integration,…
Event system patterns — C# events, UnityEvent, SO event channels, static EventBus. When to use each, zero-allocation patterns, memory leak prevention.
Configures Claude Code's statusline to display Unity workflow state — current phase, active agent, files modified, and session duration.
Post-debugging knowledge extraction — captures non-obvious, codebase-specific learnings that pass quality gates. Invoke after resolving tricky bugs or…