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
- Check the property for null before calling PropertyField and log the expected name.
- Verify the serialized field name matches the C# field (apply [SerializeField] and check spelling/whitespace).
- Use nameof() on the backing field to avoid string typos: FindProperty(nameof(m_Field)).
- 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
- Use nameof() for FindProperty string arguments to catch renames at compile time.
- Null-check every SerializedProperty before passing it to PropertyField.
- Re-fetch SerializedObject/SerializedProperty in OnEnable after domain reloads.
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
- No valid types in required type list
- Parameter selected must be of type System.Enum
- Parameter enumValue must be of type System.Enum
- Unsupported enum base type for {0}
- Specified enumType must be System.Enum
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/96464b9d6ae0eeda.
Report an issue: GitHub.