serialization-safety

Enforce Unity serialization best practices to prevent silent data loss.

3|Updated Apr 8, 2026
One-click install
npx skills add https://github.com/XeldarAlz/KlondikeSolitaire --skill serialization-safety
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: serialization-safety
Source: https://github.com/XeldarAlz/KlondikeSolitaire/tree/main/.claude/skills/core/serialization-safety
Command: npx skills add https://github.com/XeldarAlz/KlondikeSolitaire --skill serialization-safety

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Unity's serialization system can silently reset values when renaming fields, using incorrect null checks, or misusing SerializeField/SerializeReference, leading to data loss and hard-to-trace bugs.

Core Features & Use Cases

  • FormerlySerializedAs on renames to preserve values across refactors.
  • Correct Unity null checks to detect destroyed objects and avoid null-reference crashes.
  • SerializeField for private fields to maintain encapsulation while preserving serialization.
  • SerializeReference for polymorphic serialization to handle derived types.
  • Depth awareness and safeguards to prevent serialization depth-related issues.

Quick Start

Audit your Unity codebase and apply the above rules to prevent silent data loss.

Frequently Asked Questions about serialization-safety

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

FAQPage Schema
How do I prevent Unity serialization data loss when renaming fields?

Prevent Unity serialization data loss during field renames by applying the FormerlySerializedAs attribute, which maps old serialized names to new ones to preserve values across scenes and prefabs during refactoring.

How does SerializeReference work for polymorphic serialization in Unity?

SerializeReference enables polymorphic serialization in Unity by allowing fields to store derived type instances, ensuring derived classes are serialized correctly in scenes and ScriptableObjects rather than just their base type.

Why does Unity silently reset serialized values on ScriptableObjects?

Unity silently resets serialized values when fields are renamed without FormerlySerializedAs, when private fields lack SerializeField, or when incorrect null checks fail to detect destroyed objects, causing hard-to-trace data loss.

Can I expose private fields for Unity serialization without breaking encapsulation?

Expose private fields for Unity serialization by adding the SerializeField attribute, which maintains encapsulation by keeping fields private while ensuring their values are preserved in scenes, prefabs, and ScriptableObjects.

What is the correct way to do null checks on destroyed Unity objects?

Correct Unity null checks use the custom equality operators overridden by UnityEngine.Object to detect destroyed instances, preventing null-reference crashes that standard C# null checks miss in serialized data.

Are there serialization depth limitations in Unity I should be aware of?

Unity has serialization depth safeguards to prevent infinite recursion and stack overflows; awareness of these limits ensures complex nested references using SerializeReference do not exceed the safe serialization depth.