{"record":{"id":"96464b9d6ae0eeda","repo":"Unity-Technologies/UnityCsReference","slug":"serializedproperty-is-null","errorCode":null,"errorMessage":"SerializedProperty is null","messagePattern":"SerializedProperty is null","errorType":"exception","errorClass":"NullReferenceException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/EditorGUI.cs","lineNumber":7286,"sourceCode":"            {\n                DoPropertyFieldKeyboardHandling(s_PendingPropertyKeyboardHandling);\n            }\n\n            // Properties can be nested, so A BeginProperty may not be followed by its corresponding EndProperty\n            // before there have been one or more pairs of BeginProperty/EndProperty in between.\n            // The keyboard handling for a property (that handles duplicate and delete commands for array items)\n            // uses EditorGUI.lastControlID so it has to be executed for a property before any possible child\n            // properties are handled. However, it can't be done in it's own BeginProperty, because the controlID\n            // for the property is not yet known at that point. For that reason we mark the keyboard handling as\n            // pending and handle it either the next BeginProperty call (for the first child property) or if there's\n            // no child properties, then in the matching EndProperty call.\n            s_PendingPropertyKeyboardHandling = property;\n\n            if (property == null)\n            {\n                string error = (label == null ? \"\" : label.text + \": \") + \"SerializedProperty is null\";\n                HelpBox(totalPosition, \"null\", MessageType.Error);\n                throw new NullReferenceException(error);\n            }\n\n            if (Highlighter.IsSearchingForIdentifier())\n                Highlighter.HighlightIdentifier(totalPosition, property.propertyPath);\n\n            s_PropertyFieldTempContent.text = (label == null) ? property.localizedDisplayName : label.text; // no necessary to be translated.\n            s_PropertyFieldTempContent.tooltip = (label == null || string.IsNullOrEmpty(label.tooltip)) ? property.tooltip : label.tooltip;\n            s_PropertyFieldTempContent.image = label?.image;\n\n            // In inspector debug mode & when holding down alt. Show the property path of the property.\n            if (Event.current.alt && property.serializedObject.inspectorMode != InspectorMode.Normal)\n            {\n                if (string.IsNullOrEmpty(label.text))\n                {\n                    s_PropertyFieldTempContent.tooltip = property.propertyPath;\n                }\n                else\n                {","sourceCodeStart":7268,"sourceCodeEnd":7304,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/EditorGUI.cs#L7268-L7304","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar prop = serializedObject.FindProperty(\"m_Filed\"); // typo\nEditorGUILayout.PropertyField(prop);\n\n// after\nvar prop = serializedObject.FindProperty(nameof(target.field));\nif (prop != null) EditorGUILayout.PropertyField(prop);\nelse Debug.LogError(\"Property not found: \" + nameof(target.field));","handlingStrategy":"validation","validationCode":"if (property == null) { Debug.LogError($\"Property '{name}' not found on {target}\"); return; }","typeGuard":"static bool HasProperty(SerializedObject so, string name) => so != null && so.FindProperty(name) != null;","tryCatchPattern":null,"preventionTips":["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."],"tags":["csharp","unity-editor","serializedproperty","inspector","null-guard"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}