Human-written article

What Is [field: SerializeField] in Unity and Why I Don't Use

What Is [field: SerializeField] in Unity and Why I Don't Use

TL;DR: I still avoid [field: SerializeField] for gameplay state. It looks clean, but Unity serializes the compiler generated backing field, not the property. That detail bites teams during Inspector debugging. It reduces boilerplate without giving me stronger architecture. I prefer private serialized fields with controlled access paths, so mutation stays safe in production.

After I published my article about public fields, a lot of people told me about [field: SerializeField]. The point was fair. It keeps Inspector support and reduces boilerplate. I understand why people like it. I still do not use it for gameplay state that must stay safe in production. My issue is simple. It makes mutation look cleaner, but it does not give me stronger Unity architecture by itself. In this article I explain what this attribute does, where it can break trust in a team workflow, and why I still use private serialized fields with controlled access paths.

If you want the full context for this topic, read my previous article Unity C# Architecture, Why You Should Stop Using Public Fields.

Why does [field: SerializeField] create confusion in Unity projects?

It looks clean because it is one line, but it hides what Unity is actually serializing. Most people read the property and assume the property is the data source. It is not. Unity serializes the generated backing field, and that detail is easy to miss when someone debugs broken values in the Inspector.

Here is what that looks like in code. The [field: ...] part targets the hidden backing storage for the auto-property, not the property keyword itself.

[field: SerializeField]
public int Health { get; set; } = 100;

Do not confuse [field: SerializeField] with [SerializeField]. [field: SerializeField] exposes an auto-property backing field in the Inspector. [SerializeField] exposes a field you explicitly declared.

Hint, what is a backing field?

A backing field is the real variable that holds the value in memory.
The property is just a wrapper for reading or writing that value.
With [field: SerializeField], Unity serializes that hidden storage field, not the property itself.

Hint, what is an auto property?

An auto property is the short form where I write accessors with empty bodies, like public int Health { get; set; }. The C# compiler creates a private backing field for me. I never type that field name in source. That is why [field: SerializeField] exists. It lets me attach attributes to that compiler generated field so Unity can serialize it.

How does [field: SerializeField] change serialized field names in Unity?

When I serialize a normal private field, the serialized data maps to a field I explicitly wrote. I can search it, rename it with intention, and review it during refactors. With [field: SerializeField], I depend on compiler generated backing storage. That extra layer makes serialization harder to track when multiple people touch the same code.

In a simple script this can look harmless. In a large project with prefabs, ScriptableObjects, and multiple scenes, that hidden mapping can cost hours when data stops lining up with code changes.

Can renaming a [field: SerializeField] property reset Inspector data?

Yes, and this is the risk many teams discover late. A rename that feels safe in C# can break serialized links in Unity when the property is tied to serialized backing data. The code change looks small, then a designer opens content and sees settings reset.

I have seen this type of failure create expensive cleanup work. Someone fixes naming, pushes a commit, and everything looks fine until content creators report missing values. Then the team needs restore work, asset audits, and backtracking.

Why is [field: SerializeField] risky in team production workflows?

In team projects, renaming and refactoring are normal. Designers and technical artists depend on serialized values staying stable. If serialized behavior is less obvious in code review, a harmless looking cleanup can turn into a content incident days later.

That is why I call this a trust problem. The architecture should make serialization behavior explicit for everyone, not just for the person who wrote the original script.

Does [field: SerializeField] protect state, or just expose it differently?

Most of the time it exposes state differently. The syntax looks modern and compact, but state safety still depends on write control. If any system can still change critical gameplay values without a guarded path, the architecture is still fragile.

Cleaner syntax is not the same as safer code.

Why do I still use private fields and public getters instead?

I use private serialized fields because they make persistence explicit in Unity. I expose read access through getters, and I force writes through methods or controlled setters where I clamp values and run side effects.

Here is the same pattern I use in my public fields article, private serialized backing fields with guarded properties.

using UnityEngine;

public class NPC : MonoBehaviour
{
    [SerializeField] private int _health = 100;
    [SerializeField] private int _maxHealth = 100;

    public int Health
    {
        get { return _health; }
        set { _health = Mathf.Clamp(value, 0, _maxHealth); }
    }

    public int MaxHealth
    {
        get { return _maxHealth; }
        set { _maxHealth = Mathf.Max(1, value); }
    }
}

This takes a few more characters, but it keeps state boundaries clear and consistent across my architecture content. It also makes refactors safer and debugging faster when projects grow.

Should I ever use [field: SerializeField]?

I do not treat this as a forbidden feature. For prototypes, throwaway scripts, and low risk tooling, it can be fine. I avoid it in production gameplay systems where serialized stability and controlled writes are non negotiable.

My rule is straightforward. If the value matters for game rules, I keep state explicit and write paths controlled.

If you are deciding between convenience and long term safety, I would pick explicit architecture every time.

Read more Unity architecture articles

1. Unity Code Architecture and Dependency Injection

2. I Researched UI Toolkit So You Don't Have To

3. What is Unity DOTS. Should you learn it in 2026? Is it useful?