Unity-Technologies/UnityCsReference · error · NullReferenceException

SerializedProperty is null

Error message

SerializedProperty is null

What it means

Thrown inside the property-rendering pipeline (the BeginProperty/PropertyField path) when the supplied SerializedProperty is null. Unity renders an error HelpBox first, then throws NullReferenceException with a label-prefixed message so the inspector surfaces a clear failure rather than a silent null dereference deeper in the C++ bindings.

Source

Thrown at Editor/Mono/EditorGUI.cs:7286

            {
                DoPropertyFieldKeyboardHandling(s_PendingPropertyKeyboardHandling);
            }

            // Properties can be nested, so A BeginProperty may not be followed by its corresponding EndProperty
            // before there have been one or more pairs of BeginProperty/EndProperty in between.
            // The keyboard handling for a property (that handles duplicate and delete commands for array items)
            // uses EditorGUI.lastControlID so it has to be executed for a property before any possible child
            // properties are handled. However, it can't be done in it's own BeginProperty, because the controlID
            // for the property is not yet known at that point. For that reason we mark the keyboard handling as
            // pending and handle it either the next BeginProperty call (for the first child property) or if there's
            // no child properties, then in the matching EndProperty call.
            s_PendingPropertyKeyboardHandling = property;

            if (property == null)
            {
                string error = (label == null ? "" : label.text + ": ") + "SerializedProperty is null";
                HelpBox(totalPosition, "null", MessageType.Error);
                throw new NullReferenceException(error);
            }

            if (Highlighter.IsSearchingForIdentifier())
                Highlighter.HighlightIdentifier(totalPosition, property.propertyPath);

            s_PropertyFieldTempContent.text = (label == null) ? property.localizedDisplayName : label.text; // no necessary to be translated.
            s_PropertyFieldTempContent.tooltip = (label == null || string.IsNullOrEmpty(label.tooltip)) ? property.tooltip : label.tooltip;
            s_PropertyFieldTempContent.image = label?.image;

            // In inspector debug mode & when holding down alt. Show the property path of the property.
            if (Event.current.alt && property.serializedObject.inspectorMode != InspectorMode.Normal)
            {
                if (string.IsNullOrEmpty(label.text))
                {
                    s_PropertyFieldTempContent.tooltip = property.propertyPath;
                }
                else
                {

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Check the property for null before calling PropertyField and log the expected name.
  2. Verify the serialized field name matches the C# field (apply [SerializeField] and check spelling/whitespace).
  3. Use nameof() on the backing field to avoid string typos: FindProperty(nameof(m_Field)).
  4. Re-fetch the SerializedObject/SerializedProperty in OnEnable after assembly reload.

Example fix

// before
var prop = serializedObject.FindProperty("m_Filed"); // typo
EditorGUILayout.PropertyField(prop);

// after
var prop = serializedObject.FindProperty(nameof(target.field));
if (prop != null) EditorGUILayout.PropertyField(prop);
else Debug.LogError("Property not found: " + nameof(target.field));
Defensive patterns

Strategy: validation

Validate before calling

if (property == null) { Debug.LogError($"Property '{name}' not found on {target}"); return; }

Type guard

static bool HasProperty(SerializedObject so, string name) => so != null && so.FindProperty(name) != null;

Prevention

When it happens

Trigger: Calling EditorGUI.PropertyField (or any path through the property rendering internals) with a null SerializedProperty. Common when FindProperty returns null because the property name was misspelled or the object's serialization changed.

Common situations: SerializedObject.FindProperty("m_WrongName") returns null and is passed straight to PropertyField; a custom inspector that drops a field but forgets to update the FindProperty calls; a SerializedProperty captured before a domain reload becoming stale.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/96464b9d6ae0eeda. Report an issue: GitHub.