Unity-Technologies/UnityCsReference · error · ArgumentException

Cannot apply added component. Component is not an added comp

Error message

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

What it means

Thrown by ApplyAddedComponent when the component is non-null but PrefabUtility.IsAddedComponentOverride(component) is false — i.e., the component is not registered as an 'added component' override on a prefab instance. Apply only makes sense for components that exist on the instance but not on the source asset, so a regular inherited component is rejected with ArgumentException.

Source

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

            for (int i = 0; i < originalComponentOrder.Length; ++i)
            {
                if (originalComponentOrder[i] != newComponentOrder[i])
                    return true;
            }

            return false;
        }

        public static void ApplyAddedComponent(Component component, string assetPath, InteractionMode action)
        {
            DateTime startTime = DateTime.UtcNow;

            if (component == null)
                throw new ArgumentNullException(nameof(component), "Cannot apply added component. Component is null.");

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

            ThrowExceptionIfInstanceIsPersistent(component);

            try
            {
                GameObject prefabSourceGameObject = GetCorrespondingObjectFromSourceAtPath(component.gameObject, assetPath);
                if (prefabSourceGameObject == null)
                    return;

                var originalComponentOrder = component.gameObject.GetComponents<Component>();

                var actionName = "Apply Added Component";
                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.Apply).Select(ObjectNames.GetInspectorTitle));

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Guard with: if (!PrefabUtility.IsAddedComponentOverride(component)) return; or route to ApplyObjectOverride instead.
  2. Confirm the component is genuinely an added override (present on instance, absent on asset) before applying.
  3. Use the correct API: ApplyObjectOverride for modified existing components, ApplyAddedComponent only for added ones.

Example fix

// before
PrefabUtility.ApplyAddedComponent(comp, assetPath, InteractionMode.UserAction);

// after
if (PrefabUtility.IsAddedComponentOverride(comp))
    PrefabUtility.ApplyAddedComponent(comp, assetPath, InteractionMode.UserAction);
else
    PrefabUtility.ApplyObjectOverride(comp, assetPath, InteractionMode.UserAction);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!PrefabUtility.IsAddedComponentOverride(component))
{ PrefabUtility.ApplyObjectOverride(component, assetPath, action); return; }
PrefabUtility.ApplyAddedComponent(component, assetPath, action);

Type guard

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

Prevention

When it happens

Trigger: Calling ApplyAddedComponent on a component that already exists on the prefab asset (an overridden component, not an added one); passing a component on a non-prefab GameObject; passing a component on a plain scene object.

Common situations: Bulk override tooling that assumes every component is an added override; confusion between ApplyPropertyOverride (for modified components) and ApplyAddedComponent (for new components); applying a component that was reverted and is no longer an override.

Related errors


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