serialization-safety

Review Unity C# serialization changes for data-loss and runtime risks.

3|Updated Jun 27, 2026
One-click install
npx skills add https://github.com/OmerZeyveli/kinglet-unity --skill serialization-safety-omerzeyveli
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: serialization-safety
Source: https://github.com/OmerZeyveli/kinglet-unity/tree/main/.claude/skills/core/serialization-safety
Command: npx skills add https://github.com/OmerZeyveli/kinglet-unity --skill serialization-safety-omerzeyveli

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill prevents silent data loss in Unity scenes, prefabs, and ScriptableObjects caused by unsafe field renames, unsupported types, incorrect null checks, and improper serialization configuration.

Core Features & Use Cases

  • Rename Protection: Preserves existing serialized values with FormerlySerializedAs when fields are renamed.
  • Serialization Guidance: Defines when to use SerializeField, SerializeReference, NonSerialized, and ISerializationCallbackReceiver for supported and unsupported data types.
  • Unity Runtime Safety: Prevents incorrect C# null checks on destroyed Unity objects and clarifies serialization depth and inspector behavior.
  • Use Case: Apply these rules while refactoring a MonoBehaviour or ScriptableObject to preserve configured production data and avoid runtime failures caused by destroyed object references.

Quick Start

Use the serialization-safety skill to review this Unity C# change for data-loss risks, unsafe null checks, and missing serialization attributes.

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 data loss when renaming serialized fields?

Use the FormerlySerializedAs attribute on renamed fields to preserve existing serialized values in Unity MonoBehaviours and ScriptableObjects, preventing silent data loss during scene and prefab refactoring.

When should I use SerializeReference instead of SerializeField in Unity?

Use SerializeReference for polymorphic data and unsupported types like interfaces or dictionaries, while SerializeField exposes standard supported types to the Unity inspector without requiring public access modifiers.

Why does my Unity null check fail on destroyed objects at runtime?

Standard C# null checks fail on destroyed Unity objects because the native object is gone but the managed wrapper persists. Unity-aware null comparison patterns are required for accurate runtime safety checks.

How do I serialize a dictionary in a Unity ScriptableObject?

To serialize a dictionary in a Unity ScriptableObject, implement ISerializationCallbackReceiver to handle custom serialization logic, because Unity does not natively support dictionary serialization for scene or prefab data.

Can I use NonSerialized to exclude fields from Unity prefabs?

Yes, you can use the NonSerialized attribute to exclude fields from Unity serialization, ensuring they are not saved in prefabs or scenes and maintaining proper serialization configuration for runtime-only data.