Unity-Technologies/UnityCsReference · error · ArgumentException

Provided GameObject is not a Prefab instance

Error message

Provided GameObject is not a Prefab instance

What it means

Thrown by ApplyPrefabInstance when the provided GameObject is not part of any non-asset Prefab instance (IsPartOfNonAssetPrefabInstance returns false). ApplyPrefabInstance only operates on scene-level Prefab instances; a plain GameObject or a Prefab asset itself is not eligible.

Source

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

            }

            return assetRoot;
        }

        internal static void ApplyPrefabInstance(GameObject instance)
        {
            if (instance == null)
                throw new ArgumentNullException(nameof(instance));

            // Include model check even though models are also immutable, since we can give a more clear exception message.
            if (IsPartOfModelPrefab(instance))
                throw new ArgumentException("Can't apply to a Model Prefab");

            if (IsPartOfImmutablePrefab(instance))
                throw new ArgumentException("Can't apply to an immutable Prefab");

            if (!IsPartOfNonAssetPrefabInstance(instance))
                throw new ArgumentException("Provided GameObject is not a Prefab instance");

            var root = GetOutermostPrefabInstanceRoot(instance);
            if (root != instance)
                throw new ArgumentException("GameObject to save Prefab from must be a Prefab root");

            var assetObject = GetCorrespondingObjectFromSource(instance);
            string path = AssetDatabase.GetAssetPath(assetObject);

            SaveAsPrefabAssetArgumentCheck(instance, path, true);

            Internal_CallPrefabInstanceApplying(instance);

            ApplyPrefabInstance_Internal(instance);

            Internal_CallPrefabInstanceApplied(instance);
        }

        // Can't use UnityUpgradable since it doesn't currently support swapping parameter order.

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Confirm the GameObject is a Prefab instance: PrefabUtility.IsPartOfNonAssetPrefabInstance(go) before calling.
  2. If it's a plain GameObject, connect it to a Prefab first or use the appropriate per-override apply API.
  3. If it's a Prefab asset, edit it in Prefab Mode instead of using ApplyPrefabInstance.

Example fix

// before
PrefabUtility.ApplyPrefabInstance(plainGameObject);
// after
if (PrefabUtility.IsPartOfNonAssetPrefabInstance(plainGameObject))
    PrefabUtility.ApplyPrefabInstance(plainGameObject);
else
    Debug.LogWarning("Object is not a prefab instance.");
Defensive patterns

Strategy: type-guard

Validate before calling

if (!PrefabUtility.IsPartOfNonAssetPrefabInstance(go))
{ Debug.LogError("Object is not a prefab instance."); return; }
PrefabUtility.ApplyPrefabInstance(go);

Type guard

static bool IsNonAssetPrefabInstance(GameObject go) =>
    go != null && PrefabUtility.IsPartOfNonAssetPrefabInstance(go);

Prevention

When it happens

Trigger: Calling ApplyPrefabInstance on a plain GameObject (never connected to a Prefab) or directly on a Prefab asset in the project view.

Common situations: Developer passes an arbitrary scene GameObject that was never a Prefab instance. Confusing ApplyAddedComponent/ApplyObjectOverride with ApplyPrefabInstance. Calling apply on a newly created GameObject before connecting it to a Prefab.

Related errors


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