agentleFS
JulianKerignardJulianKerignard/Unity-Skills/skills/unity-save/SKILL.md

Unity Save System

Skill8 starsChanged 9 months agoMITView on GitHub

Implementer un systeme de sauvegarde et persistence : /unity-save, /save, sauvegarde, save system, persistence, sauvegarder, charger une partie, save game, PlayerPrefs, serialisation, JSON save, cloud save, slot de sauvegarde

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Test EditMode : save -> clear state -> load -> assert state restored

    line 86
  2. Distinctive:

    Test corruption : charger un fichier tronque -> verifier fallback .bak

    line 87
  3. Distinctive:

    Test migration : charger une save v1 avec du code v2

    line 88

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Unity Save System

Ce que fait cette skill

Guider l'implementation d'un systeme de sauvegarde complet pour Unity 6+ : serialisation de l'etat de jeu, persistence fichier avec ecriture atomique, versioning des donnees sauvegardees, gestion multi-slots, auto-save, cloud saves (UGS), et encryption optionnelle. Couvre du simple PlayerPrefs jusqu'aux architectures hybrides local/cloud.

Prerequis

  • Unity 6.0+ (Awaitable API)
  • Recommande : Newtonsoft.Json (com.unity.nuget.newtonsoft-json) pour serialisation avancee
  • Aucune dependance stricte pour les cas simples (JsonUtility suffit)

Demarrage rapide

  1. Choisir le format : JsonUtility (simple) ou Newtonsoft.Json (polymorphisme, Dictionary)
  2. Creer l'interface ISaveable sur chaque composant a sauvegarder
  3. Implementer SaveManager avec ecriture atomique dans Application.persistentDataPath
  4. Brancher l'auto-save (dirty flag + timer + OnApplicationPause)
  5. Tester le cycle save/load avec un test EditMode (voir /unity-test)

Arbre de decision

Que sauvegarder ?
|
+-- Preferences utilisateur (volume, langue, bindings) ?
|   +-- Peu de donnees (<1 KB) --> PlayerPrefs
|   +-- Plus structure ----------> JSON dans persistentDataPath
|
+-- Etat de jeu (progression, inventaire, position) ?
|   +-- Slot unique -----------> JSON + ISaveable pattern
|   +-- Multi-slots -----------> SaveManager avec index + slots nommes
|   +-- Donnees volumineuses (>10 MB) --> Format binaire (MemoryPack/MessagePack)
|
+-- Cloud sync ?
|   +-- Unity Gaming Services --> UGS Cloud Save
|   +-- Cross-platform natif --> Platform Toolkit (Unity 6.3+)
|   +-- Hybride (local + cloud) -> ISaveStorage abstraction (voir `references/save-advanced.md`)
|
+-- Sensible (anti-cheat) ?
    +-- Encryption AES + hash d'integrite (voir `references/save-advanced.md`)

Guide etape par etape

Etape 1 — Choisir le format de serialisation

CritereJsonUtilityNewtonsoft.JsonMemoryPackMessagePack
SetupInclus UnityPackage UnityNuGetNuGet
PolymorphismeNonOui (TypeNameHandling)OuiOui
DictionaryNonOuiOuiOui
LisibiliteJSONJSONBinaireBinaire
PerformanceRapideMoyenTres rapideRapide
TailleMoyenMoyenPetitPetit
RecommandationPrototypageDefaut recommande>10 MB donneesAlternative binaire

Etape 2 — Creer ISaveable et SaveData

  • Definir ISaveable : SaveKey, CaptureState(), RestoreState(object)
  • Creer SaveData avec champ version, Dictionary<string, object>, metadata
  • Voir references/save-templates.md pour le code complet (ISaveable, SaveData, SaveManager)

Etape 3 — Implementer SaveManager

  • Pattern singleton ou service locator (voir /unity architecture)
  • Registry de ISaveable (Register/Unregister)
  • SaveAsync : capturer tous les etats -> serialiser -> ecriture atomique (.tmp -> .save, .bak)
  • LoadAsync : lire fichier -> deserialiser -> restaurer tous les etats
  • Chemin : Path.Combine(Application.persistentDataPath, "saves", slotName + ".save")

Etape 4 — Auto-save

  • Dirty flag : chaque ISaveable signale ses changements
  • Timer configurable (60-120s par defaut)
  • Sauvegarder sur OnApplicationPause(true) et changement de scene
  • Voir references/save-advanced.md section Auto-Save

Etape 5 — Tester le cycle save/load

  • Test EditMode : save -> clear state -> load -> assert state restored
  • Test corruption : charger un fichier tronque -> verifier fallback .bak
  • Test migration : charger une save v1 avec du code v2

Regles strictes

TOUJOURS

  • TOUJOURS utiliser l'ecriture atomique (write .tmp, rename, keep .bak)
  • TOUJOURS versionner les SaveData (champ version incremente a chaque changement de schema)
  • TOUJOURS utiliser Application.persistentDataPath (jamais dataPath ou streamingAssetsPath)
  • TOUJOURS sauvegarder sur OnApplicationPause(true) pour mobile
  • TOUJOURS serialiser des POCOs (Plain Old C# Objects) — pas de types Unity
  • TOUJOURS gerer le cas "pas de sauvegarde" (premier lancement)

JAMAIS

  • JAMAIS utiliser BinaryFormatter — faille de securite connue, deprecie
  • JAMAIS stocker de references MonoBehaviour, GameObject, ou ScriptableObject dans les saves
  • JAMAIS sauvegarder sur le thread principal de facon synchrone pour des fichiers >100 KB
  • JAMAIS supprimer l'ancien fichier avant que le nouveau soit ecrit (corruption garantie en cas de crash)
  • JAMAIS ignorer les exceptions d'I/O — toujours try/catch avec fallback

Skills connexes

  • /unity-code-gen — Generer le boilerplate ISaveable et SaveManager
  • /unity-test — Tests EditMode pour valider le cycle save/load
  • /unity-debug — Diagnostiquer les problemes de deserialisation
  • /addressables — Sauvegarder les references d'assets par address string

Troubleshooting

ProblemeCause probableSolution
FileNotFoundException au loadPremier lancement, aucune saveVerifier File.Exists() avant load, retourner donnees par defaut
Donnees perdues apres mise a jourSchema change sans migrationAjouter champ version + chaine de migration v1->v2->vN
JsonSerializationExceptionType polymorphe non reconnuNewtonsoft : TypeNameHandling.Auto + SerializationBinder custom
Save corrompue (JSON tronque)Crash pendant ecritureEcriture atomique (.tmp -> rename) + fallback sur .bak
UnauthorizedAccessExceptionChemin non autorise (Android scope)Utiliser uniquement persistentDataPath
PlayerPrefs disparaissent (iOS)Nettoyage systeme ou reinstallationMigrer vers fichier pour donnees importantes
Save trop volumineuse (>50 MB)Serialisation JSON de gros volumesPasser a MemoryPack/MessagePack, compresser (GZip)
Desync cloud/localConflit de versionsImplementer conflict resolution (timestamp ou version counter)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.