Unity-Technologies/UnityCsReference · error · ArgumentException

Cannot revert added component. Component is not an added com

Error message

Cannot revert added component. Component is not an added component override on a Prefab instance.

What it means

Thrown by RevertAddedComponent when component is non-null but PrefabUtility.IsAddedComponentOverride(component) is false. Revert of an 'added component' override only applies to components that were added on the instance relative to the asset; a regular inherited/overridden component is rejected with ArgumentException.

Source

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

            }

            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(
                        L10n.Tr("Can't revert added component {0} because {1} depends on it."),
                        ObjectNames.GetInspectorTitle(component),
                        dependentComponents);

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Guard with: if (!PrefabUtility.IsAddedComponentOverride(component)) return; or use RevertObjectOverride for modified components.
  2. Verify the component is an added override before reverting.
  3. Use the correct revert API per override kind (added component vs property override vs removed component).

Example fix

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

// after
if (PrefabUtility.IsAddedComponentOverride(comp))
    PrefabUtility.RevertAddedComponent(comp, InteractionMode.UserAction);
else
    PrefabUtility.RevertObjectOverride(comp, InteractionMode.UserAction);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!PrefabUtility.IsAddedComponentOverride(component))
{ PrefabUtility.RevertObjectOverride(component, action); return; }
PrefabUtility.RevertAddedComponent(component, action);

Type guard

static bool IsAddedOverride(Component c)
    => c != null && PrefabUtility.IsAddedComponentOverride(c);

Prevention

When it happens

Trigger: Calling RevertAddedComponent on a component that exists on the asset (so it is an override, not an addition); reverting a component on a non-prefab GameObject; reverting after the override was already applied/cleared.

Common situations: Generic override-revert tooling that routes every component through RevertAddedComponent; confusing revert of a modified component (RevertObjectOverride) with revert of an added component; double-revert after state already cleared.

Related errors


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