🤔

Serializing a field#

Fields#

Mark your variable with a [SerializeField] attribute:

[SerializeField] private float _value;

or make it public:

public float Value;
warning

A static, const, or readonly field cannot be serialized.

Properties#

Unity doesn't serialize properties. You can serialize the backing field of an auto-property using [field: SerializeField]. Versions before 2020 the names did not display appropriately in the Inspector.

[field: SerializeField]
public float Value { get; private set; }
warning

The property must have a set accessor, and cannot be static.

Reasons to avoid serializing compiler-generated backing fields#


My variable is still not appearing in the inspector.