-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserialization-rules.mdc
More file actions
21 lines (19 loc) · 918 Bytes
/
Copy pathserialization-rules.mdc
File metadata and controls
21 lines (19 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---
title: Serialization rules
description: Unity serialization best practices
globs: ["**/*.cs"]
alwaysApply: false
standards-version: 1.10.0
---
# Unity serialization rules
- Unity serializes: public fields, [SerializeField] private fields
- Unity does NOT serialize: properties, static fields, readonly fields, dictionaries
- Use [SerializeField] private over public for encapsulation
- Use [HideInInspector] to serialize but hide from inspector
- Use [NonSerialized] or [System.NonSerialized] to exclude public fields
- Use [Header("Section")] and [Space] to organize inspector fields
- Use [Tooltip("description")] for inspector documentation
- Use [Range(min, max)] for numeric sliders
- Nested serializable classes need [System.Serializable]
- ScriptableObject references survive play mode; MonoBehaviour field values reset
- For complex data: use JSON serialization (JsonUtility or Newtonsoft) for save/load