Unity-Technologies/UnityCsReference · error · ArgumentException

Calling apply methods on an instance which is part of a Pref

Error message

Calling apply methods on an instance which is part of a Prefab Asset is not supported.

What it means

Thrown by ThrowExceptionIfInstanceIsPersistent when an apply operation is requested on an object that is persistent (EditorUtility.IsPersistent is true), i.e. part of a Prefab Asset on disk rather than a scene instance. Unity supports revert on prefab assets but explicitly forbids apply on assets, since apply pushes instance overrides back to a source — meaningless for an asset.

Source

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

                ThrowExceptionIfInstanceIsPersistent(prefabInstanceObject);
        }

        static void ThrowExceptionIfAllPrefabInstanceObjectsAreInvalid(Object[] prefabInstanceObjects, bool isApply)
        {
            foreach (var obj in prefabInstanceObjects)
            {
                if (obj != null && (obj is GameObject || obj is Component) && IsPartOfPrefabInstance(obj) && !(isApply && EditorUtility.IsPersistent(obj)))
                    return;
            }

            // Throw exception if all objects are invalid
            throw new ArgumentException("Cannot apply or revert on any of the objects. Attempt with individual objects for details.", nameof(prefabInstanceObjects));
        }

        static void ThrowExceptionIfInstanceIsPersistent(Object prefabInstanceObject)
        {
            if (EditorUtility.IsPersistent(prefabInstanceObject))
                throw new ArgumentException("Calling apply methods on an instance which is part of a Prefab Asset is not supported.", nameof(prefabInstanceObject));
        }

        public static GameObject[] FindAllInstancesOfPrefab(GameObject prefabRoot)
        {
            return FindAllInstancesOfPrefab_internal(prefabRoot, SceneHandle.None);
        }

        public static GameObject[] FindAllInstancesOfPrefab(GameObject prefabRoot, Scene scene)
        {
            if (!scene.IsValid())
            {
                throw new ArgumentException("Input scene is not valid: Could not be found.");
            }

            return FindAllInstancesOfPrefab_internal(prefabRoot, scene.handle);
        }

        public static void MergePrefabInstance(GameObject instanceRoot)

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. For apply, operate on a scene instance of the prefab, not the asset.
  2. To change the asset, edit it in Prefab Mode or modify and save via PrefabUtility.SaveAsPrefabAsset instead of apply.
  3. Use revert (not apply) if you must operate on the asset directly.

Example fix

// before
// obj is a prefab asset selected in the Project window
PrefabUtility.ApplyPrefabOverride(obj, path); // throws

// after
// Instantiate into a scene, apply, then optionally save
var instance = (GameObject)PrefabUtility.InstantiatePrefab(obj);
PrefabUtility.ApplyPrefabOverride(instance, path);
Defensive patterns

Strategy: validation

Validate before calling

if (isApply && UnityEditor.EditorUtility.IsPersistent(obj))
{ Debug.LogWarning("Apply is not supported on prefab assets; use a scene instance."); return; }

Type guard

static bool CanApply(UnityEngine.Object o) =>
    (o is GameObject || o is Component) && !UnityEditor.EditorUtility.IsPersistent(o);

Prevention

When it happens

Trigger: Calling an apply method (isApply=true) on a GameObject/Component that is part of a prefab asset in the Project, or on an object inside an open Prefab edit stage (which is persistent during editing).

Common situations: Editing a prefab in Prefab Mode and invoking an apply action. Selecting a prefab asset in the Project window and running an apply tool. Confusing apply (instance→source) with editing the asset directly.

Related errors


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