Unity-Technologies/UnityCsReference · error · ArgumentException

Cannot apply added GameObject. GameObject '{go.name}' is not

Error message

Cannot apply added GameObject. GameObject '{go.name}' is not an added GameObject override on a Prefab instance.

What it means

Each element must be an 'added GameObject override' — a GameObject that was added to a prefab instance and does not exist in the source prefab asset. Verified via PrefabUtility.IsAddedGameObjectOverride(go). Applying an object that is not an addition is meaningless and is rejected.

Source

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

        }

        public static void ApplyAddedGameObjects(GameObject[] gameObjects, string assetPath, InteractionMode action)
        {
            DateTime startTime = DateTime.UtcNow;

            if (gameObjects == null)
                throw new ArgumentNullException(nameof(gameObjects), "Cannot apply added GameObjects. GameObjects array is null.");

            if (gameObjects.Length == 0)
                throw new ArgumentException(nameof(gameObjects), "No GameObjects in array.");

            foreach (GameObject go in gameObjects)
            {
                if (go == null)
                    throw new ArgumentException(nameof(go), "Input GameObject is null.");

                if (!IsAddedGameObjectOverride(go))
                    throw new ArgumentException(nameof(go), $"Cannot apply added GameObject. GameObject '{go.name}' is not an added GameObject override on a Prefab instance.");

                ThrowExceptionIfInstanceIsPersistent(go);
            }

            if (gameObjects.Length > 1 && !HasSameParent(gameObjects))
                throw new ArgumentException(nameof(gameObjects), "ApplyAddedGameObjects requires that GameObjects share the same parent.");

            GameObject gameObject = gameObjects[0];
            Transform instanceParent = gameObject.transform.parent;
            if (instanceParent == null)
                return;

            GameObject prefabSourceGameObjectParent = GetCorrespondingObjectFromSourceAtPath(instanceParent.gameObject, assetPath);
            if (prefabSourceGameObjectParent == null)
                return;

            var instanceRoot = GetOutermostPrefabInstanceRoot(instanceParent);
            if (instanceRoot == null)

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Check PrefabUtility.IsAddedGameObjectOverride(go) before adding the object to the array.
  2. Obtain only legitimate additions via PrefabUtility.GetAddedGameObjects(instanceRoot) or by inspecting OverrideAddedComponents/added objects.
  3. When unsure of override status, query GetPrefabOverrideStatus or HasPrefabOverride to classify first.

Example fix

// before
PrefabUtility.ApplyAddedGameObjects(selectedGos, path, mode);

// after
var added = selectedGos.Where(PrefabUtility.IsAddedGameObjectOverride).ToArray();
if (added.Length > 0)
    PrefabUtility.ApplyAddedGameObjects(added, path, mode);
Defensive patterns

Strategy: validation

Validate before calling

gameObjects = gameObjects?.Where(PrefabUtility.IsAddedGameObjectOverride).ToArray();
if (gameObjects == null || gameObjects.Length == 0) return;

Type guard

static bool IsAddedOverride(GameObject go) =>
    go != null && PrefabUtility.IsAddedGameObjectOverride(go);

Prevention

When it happens

Trigger: Passing a GameObject that exists in the source prefab (an original child), a prefab instance root, or a non-prefab object that happens to live inside the instance hierarchy.

Common situations: Confusing original prefab children with added overrides; passing the instance root; selecting siblings that were not actually added by the user.

Related errors


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