Inspector and serialization attributes
↑At a glance
Section titled “At a glance”These attributes control what Unity saves and how fields appear in the Inspector. The two questions are separate: a field can be serialized but hidden, or visible only because it is serializable.
Quick reference
Section titled “Quick reference”| Attribute | What it does | Applies to and requires |
|---|---|---|
[SerializeField] |
Make a private field part of Unity serialization and show it in the Inspector. | Field · UnityEngine |
[HideInInspector] |
Hide a serialized field from the Inspector without necessarily removing its saved data. | Field · UnityEngine |
[NonSerialized] |
Stop a public field from being serialized using the .NET attribute. | Field · System |
[FormerlySerializedAs("oldName")] |
Preserve serialized field values after a field is renamed. | Field · UnityEngine.Serialization |
[Header("Title")] |
Add a heading above a field in the Inspector. | Field · UnityEngine |
[Space] / [Space(n)] |
Add vertical space before a field in the Inspector. | Field · UnityEngine |
[Tooltip("…")] |
Show explanatory text when hovering a field label. | Field · UnityEngine |
[Range(min, max)] |
Show a slider for an int or float field in the Inspector. | Field · UnityEngine |
[Min(value)] |
Set an Inspector-side minimum for an int or float field. | Field · UnityEngine |
[Max(value)] |
Not a general built-in UnityEngine field attribute in the Unity 6 core API. | Optional package or custom drawer |
[TextArea(min, max)] |
Render a multiline text box with a height range in the Inspector. | Field · UnityEngine |
[Multiline] |
Show a string field as a multiline text field. | Field · UnityEngine |
[Delayed] |
Commit Inspector text or numeric edits on Enter or focus loss. | Field · UnityEngine |
[SerializeReference] |
Serialize managed object references, including supported polymorphic graphs. | Field · UnityEngine |
[InspectorName("Name")] |
Change the displayed Inspector label. | Field or enum member · UnityEngine |
[ContextMenuItem("Title", "Method")] |
Add a context-menu entry to a field which calls a method. | Field · UnityEngine |
[NonReorderable] |
Disable drag-to-reorder controls for an Inspector array or list. | Field · UnityEngine |
How to choose
Section titled “How to choose”[SerializeField]
Section titled “[SerializeField]”Make a private field part of Unity serialization and show it in the Inspector.
Use it when: Expose a tuning value while keeping access private.
Be aware: The type must meet Unity serialization rules. This does not expose a C# property.
Reference: Unity documentation
[HideInInspector]
Section titled “[HideInInspector]”Hide a serialized field from the Inspector without necessarily removing its saved data.
Use it when: Retain saved state that should not be adjusted by ordinary Inspector edits.
Be aware: Hiding a field is not the same as disabling serialization or making it secret.
Reference: Unity documentation
[NonSerialized]
Section titled “[NonSerialized]”Stop a public field from being serialized using the .NET attribute.
Use it when: Keep a public runtime cache out of scene and prefab data.
Be aware: Use [System.NonSerialized], not a UnityEngine attribute.
Reference: Unity documentation
[FormerlySerializedAs("oldName")]
Section titled “[FormerlySerializedAs("oldName")]”Preserve serialized field values after a field is renamed.
Use it when: Rename a field in a component used by existing scenes and prefabs.
Be aware: Provide the previous serialized name and test old scenes, prefabs and assets.
Reference: Unity documentation
[Header("Title")]
Section titled “[Header("Title")]”Add a heading above a field in the Inspector.
Use it when: Visually divide settings for movement, audio or gameplay.
Be aware: Inspector presentation only; it does not group fields into a new serialized object.
Reference: Unity documentation
[Space] / [Space(n)]
Section titled “[Space] / [Space(n)]”Add vertical space before a field in the Inspector.
Use it when: Add a little breathing room between unrelated Inspector settings.
Be aware: Avoid using many Space attributes to replace sensible naming and grouping.
Reference: Unity documentation
[Tooltip("…")]
Section titled “[Tooltip("…")]”Show explanatory text when hovering a field label.
Use it when: Explain units or an unusual setting without cluttering the field name.
Be aware: Good for explaining units and expected values, not for replacing API documentation.
Reference: Unity documentation
[Range(min, max)]
Section titled “[Range(min, max)]”Show a slider for an int or float field in the Inspector.
Use it when: Choose a speed, volume or other numeric setting with a bounded slider.
Be aware: This controls Inspector input, not arbitrary assignments made by code at runtime.
Reference: Unity documentation
[Min(value)]
Section titled “[Min(value)]”Set an Inspector-side minimum for an int or float field.
Use it when: Avoid negative or zero values when editing counts and sizes.
Be aware: Validate or clamp runtime values separately.
Reference: Unity documentation
[Max(value)]
Section titled “[Max(value)]”Not a general built-in UnityEngine field attribute in the Unity 6 core API.
Use it when: Only use when the installed package actually provides this attribute.
Be aware: Some third-party/Unity packages define similarly named attributes. Check the package namespace before using one.
Reference: Unity documentation
[TextArea(min, max)]
Section titled “[TextArea(min, max)]”Render a multiline text box with a height range in the Inspector.
Use it when: Let designers enter descriptions or dialogue across several lines.
Be aware: The min/max arguments relate to visible lines, not a string length limit.
Reference: Unity documentation
[Multiline]
Section titled “[Multiline]”Show a string field as a multiline text field.
Use it when: Make a short multiline text field more convenient in the Inspector.
Be aware: For larger notes or a selectable height range, consider TextArea.
Reference: Unity documentation
[Delayed]
Section titled “[Delayed]”Commit Inspector text or numeric edits on Enter or focus loss.
Use it when: Avoid responding to every keystroke while editing numeric settings.
Be aware: It changes editing behavior, not the timing of assignments made by scripts.
Reference: Unity documentation
[SerializeReference]
Section titled “[SerializeReference]”Serialize managed object references, including supported polymorphic graphs.
Use it when: Store different concrete implementations behind an interface in a managed object graph.
Be aware: Not for UnityEngine.Object references. Concrete types must be serializable and supported.
Reference: Unity documentation
[InspectorName("Name")]
Section titled “[InspectorName("Name")]”Change the displayed Inspector label.
Use it when: Show a friendly label while retaining a stable C# identifier.
Be aware: The C# identifier and serialization field name stay unchanged.
Reference: Unity documentation
[ContextMenuItem("Title", "Method")]
Section titled “[ContextMenuItem("Title", "Method")]”Add a context-menu entry to a field which calls a method.
Use it when: Offer an occasional field-specific reset or repair command.
Be aware: This is a field context menu, not a permanently visible button.
Reference: Unity documentation
[NonReorderable]
Section titled “[NonReorderable]”Disable drag-to-reorder controls for an Inspector array or list.
Use it when: Keep a fixed-order collection from being rearranged accidentally in the Inspector.
Be aware: The collection can still change in code.
Reference: Unity documentation
Inspector before and after
Section titled “Inspector before and after”This illustration is an original, simplified mockup, not a screenshot of a specific Unity Editor version.
Without attributes
With Header, Range and Tooltip
A useful field setup
Section titled “A useful field setup”using UnityEngine;using UnityEngine.Serialization;
public sealed class PlayerSettings : MonoBehaviour{ [Header("Movement")] [Tooltip("Units per second")] [FormerlySerializedAs("moveSpeed")] [SerializeField, Range(0f, 20f)] private float speed = 5f;
[SerializeField, Min(1)] private int lives = 3;
public float Speed => speed;
private void OnValidate() { // Inspector attributes alone do not validate every runtime assignment. speed = Mathf.Clamp(speed, 0f, 20f); lives = Mathf.Max(1, lives); }}The field remains private, but the Inspector can edit it. Other scripts receive read-only access through the property. OnValidate runs in the Editor; if values also arrive from runtime data, validate them at that entry point.
