{"record":{"id":"81479d5bc96c9c13","repo":"Unity-Technologies/UnityCsReference","slug":"cannot-revert-added-component-component-is-null","errorCode":null,"errorMessage":"Cannot revert added component. Component is null.","messagePattern":"Cannot revert added component\\. Component is null\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":1260,"sourceCode":"                {\n                    throw exception;\n                }\n            }\n\n            Analytics.SendApplyEvent(\n                Analytics.ApplyScope.AddedComponent,\n                component,\n                assetPath,\n                action,\n                startTime,\n                false\n            );\n        }\n\n        public static void RevertAddedComponent(Component component, InteractionMode action)\n        {\n            if (component == null)\n                throw new ArgumentNullException(nameof(component), \"Cannot revert added component. Component is null.\");\n\n            if (!PrefabUtility.IsAddedComponentOverride(component))\n                throw new ArgumentException(\"Cannot revert added component. Component is not an added component override on a Prefab instance.\", nameof(component));\n\n            var prefabInstanceGameObject = component.gameObject;\n\n            PrefabUtility.Internal_CallPrefabInstanceReverting(prefabInstanceGameObject);\n\n            if (action == InteractionMode.UserAction)\n            {\n                string dependentComponents = string.Join(\n                    \", \",\n#pragma warning disable UA2001 // The Banned API Analyzer produces compile errors for any new Linq code. This pre-existing usage has been suppressed, but should be rewritten if possible.\n                    GetAddedComponentDependencies(component, OverrideOperation.Revert).Select(ObjectNames.GetInspectorTitle));\n#pragma warning restore UA2001\n                if (!string.IsNullOrEmpty(dependentComponents))\n                {\n                    string error = String.Format(","sourceCodeStart":1242,"sourceCodeEnd":1278,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L1242-L1278","documentation":"Thrown by RevertAddedComponent(Component, InteractionMode) when component is null — ArgumentNullException(nameof(component)). The method reads component.gameObject and calls IsAddedComponentOverride immediately, so null fails fast with the descriptive message.","triggerScenarios":"Calling RevertAddedComponent(null, ...); passing a destroyed Component; forwarding a GetComponent result that returned null.","commonSituations":"Inspector/menu actions reverting a component when the selection is empty or stale; deferred revert operations whose target was destroyed between scheduling and execution.","solutions":["Null-check before calling: if (component == null) return;","Re-resolve the component reference immediately before reverting.","Use the Unity null check (component == null) to also catch destroyed Objects."],"exampleFix":"// before\nPrefabUtility.RevertAddedComponent(c, InteractionMode.UserAction);\n\n// after\nif (c == null) return;\nPrefabUtility.RevertAddedComponent(c, InteractionMode.UserAction);","handlingStrategy":"validation","validationCode":"if (component == null) { Debug.LogWarning(\"Component is null; cannot revert.\"); return; }\nPrefabUtility.RevertAddedComponent(component, action);","typeGuard":"static bool IsLiveComponent(Component c) => c != null && c.gameObject != null;","tryCatchPattern":null,"preventionTips":["Null-check Components before revert APIs.","Re-resolve the component reference right before reverting.","Guard interactive actions against stale/destroyed selections."],"tags":["prefab","validation","null-argument","added-component"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}