{"record":{"id":"a3fa257f71addd21","repo":"Unity-Technologies/UnityCsReference","slug":"cannot-apply-added-component-component-is-not-an","errorCode":null,"errorMessage":"Cannot apply added component. Component is not an added component override on a Prefab instance.","messagePattern":"Cannot apply added component\\. Component is not an added component override on a Prefab instance\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":1171,"sourceCode":"\n            for (int i = 0; i < originalComponentOrder.Length; ++i)\n            {\n                if (originalComponentOrder[i] != newComponentOrder[i])\n                    return true;\n            }\n\n            return false;\n        }\n\n        public static void ApplyAddedComponent(Component component, string assetPath, InteractionMode action)\n        {\n            DateTime startTime = DateTime.UtcNow;\n\n            if (component == null)\n                throw new ArgumentNullException(nameof(component), \"Cannot apply added component. Component is null.\");\n\n            if (!PrefabUtility.IsAddedComponentOverride(component))\n                throw new ArgumentException(\"Cannot apply added component. Component is not an added component override on a Prefab instance.\", nameof(component));\n\n            ThrowExceptionIfInstanceIsPersistent(component);\n\n            try\n            {\n                GameObject prefabSourceGameObject = GetCorrespondingObjectFromSourceAtPath(component.gameObject, assetPath);\n                if (prefabSourceGameObject == null)\n                    return;\n\n                var originalComponentOrder = component.gameObject.GetComponents<Component>();\n\n                var actionName = \"Apply Added Component\";\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.Apply).Select(ObjectNames.GetInspectorTitle));","sourceCodeStart":1153,"sourceCodeEnd":1189,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L1153-L1189","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Guard with: if (!PrefabUtility.IsAddedComponentOverride(component)) return; or route to ApplyObjectOverride instead.","Confirm the component is genuinely an added override (present on instance, absent on asset) before applying.","Use the correct API: ApplyObjectOverride for modified existing components, ApplyAddedComponent only for added ones."],"exampleFix":"// before\nPrefabUtility.ApplyAddedComponent(comp, assetPath, InteractionMode.UserAction);\n\n// after\nif (PrefabUtility.IsAddedComponentOverride(comp))\n    PrefabUtility.ApplyAddedComponent(comp, assetPath, InteractionMode.UserAction);\nelse\n    PrefabUtility.ApplyObjectOverride(comp, assetPath, InteractionMode.UserAction);","handlingStrategy":"type-guard","validationCode":"if (!PrefabUtility.IsAddedComponentOverride(component))\n{ PrefabUtility.ApplyObjectOverride(component, assetPath, action); return; }\nPrefabUtility.ApplyAddedComponent(component, assetPath, action);","typeGuard":"static bool IsAddedOverride(Component c)\n    => c != null && PrefabUtility.IsAddedComponentOverride(c);","tryCatchPattern":null,"preventionTips":["Distinguish added-component overrides from modified-component overrides.","Route through ApplyObjectOverride for existing components, ApplyAddedComponent only for additions.","Check IsAddedComponentOverride before applying."],"tags":["prefab","validation","added-component","type-mismatch"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}