serialization-safety

Review Unity C# serialization usage to prevent silent data loss in prefabs and scenes.

Updated May 6, 2026
One-click install
npx skills add https://github.com/BasarEkinci/memory-card-game --skill serialization-safety-basarekinci
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: serialization-safety
Source: https://github.com/BasarEkinci/memory-card-game/tree/main/.claude/skills/core/serialization-safety
Command: npx skills add https://github.com/BasarEkinci/memory-card-game --skill serialization-safety-basarekinci

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It prevents Unity serialization mistakes that silently reset configured values in scenes, prefabs, and ScriptableObjects to defaults with little to no warning.

Core Features & Use Cases

  • Rename-proof serialized fields: Apply [FormerlySerializedAs] on every field rename to preserve existing saved data across versions.
  • Correct Unity null handling: Use Unity’s overloaded == behavior so destroyed objects are treated as null and won’t be called accidentally.
  • Polymorphic and structured serialization guidance: Use SerializeReference for interfaces/abstract polymorphism, NonSerialized for runtime-only caches, and ISerializationCallbackReceiver for dictionary-like data.

Quick Start

Use the serialization-safety skill to review your Unity C# fields and update renames, null checks, and serialization attributes so existing prefab and scene data remains intact.

Frequently Asked Questions about serialization-safety

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why do Unity prefab values reset to defaults after renaming a serialized field?▼

Unity prefab values reset because the serializer cannot match the renamed field to existing saved data. Applying the [FormerlySerializedAs] attribute to the renamed field preserves existing scene and prefab data across versions.

How do I serialize a dictionary or interface in Unity without losing data?▼

To serialize dictionaries or interfaces without data loss, implement ISerializationCallbackReceiver for dictionary-like data and use SerializeReference for polymorphic interfaces. This ensures structured data survives Unity's serialization cycles correctly.

What is the correct way to check for null destroyed objects in Unity C#?▼

The correct way to check for null in Unity is using its overloaded == operator. This ensures destroyed objects are accurately treated as null, preventing accidental method calls on invalid references.

When should I use NonSerialized versus SerializeField in my Unity components?▼

Use [NonSerialized] for runtime-only caches to exclude them from serialization, and use [SerializeField] to ensure private fields are saved. Correct attribute usage prevents silent data loss during scene and prefab evolution.

Does SerializeReference work for migrating prefab data in older Unity versions?▼

SerializeReference is designed for polymorphic and structured serialization of interfaces. For prefab data migration involving renamed fields, you must enforce [FormerlySerializedAs] to maintain compatibility across versions.