Unity-Technologies/UnityCsReference · error · ArgumentNullException

Cannot revert added component. Component is null.

Error message

Cannot revert added component. Component is null.

What it means

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.

Source

Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:1260

                {
                    throw exception;
                }
            }

            Analytics.SendApplyEvent(
                Analytics.ApplyScope.AddedComponent,
                component,
                assetPath,
                action,
                startTime,
                false
            );
        }

        public static void RevertAddedComponent(Component component, InteractionMode action)
        {
            if (component == null)
                throw new ArgumentNullException(nameof(component), "Cannot revert added component. Component is null.");

            if (!PrefabUtility.IsAddedComponentOverride(component))
                throw new ArgumentException("Cannot revert added component. Component is not an added component override on a Prefab instance.", nameof(component));

            var prefabInstanceGameObject = component.gameObject;

            PrefabUtility.Internal_CallPrefabInstanceReverting(prefabInstanceGameObject);

            if (action == InteractionMode.UserAction)
            {
                string dependentComponents = string.Join(
                    ", ",
#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.
                    GetAddedComponentDependencies(component, OverrideOperation.Revert).Select(ObjectNames.GetInspectorTitle));
#pragma warning restore UA2001
                if (!string.IsNullOrEmpty(dependentComponents))
                {
                    string error = String.Format(

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Null-check before calling: if (component == null) return;
  2. Re-resolve the component reference immediately before reverting.
  3. Use the Unity null check (component == null) to also catch destroyed Objects.

Example fix

// before
PrefabUtility.RevertAddedComponent(c, InteractionMode.UserAction);

// after
if (c == null) return;
PrefabUtility.RevertAddedComponent(c, InteractionMode.UserAction);
Defensive patterns

Strategy: validation

Validate before calling

if (component == null) { Debug.LogWarning("Component is null; cannot revert."); return; }
PrefabUtility.RevertAddedComponent(component, action);

Type guard

static bool IsLiveComponent(Component c) => c != null && c.gameObject != null;

Prevention

When it happens

Trigger: Calling RevertAddedComponent(null, ...); passing a destroyed Component; forwarding a GetComponent result that returned null.

Common situations: Inspector/menu actions reverting a component when the selection is empty or stale; deferred revert operations whose target was destroyed between scheduling and execution.

Related errors


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