{"record":{"id":"e297f7af374c512c","repo":"Unity-Technologies/UnityCsReference","slug":"calling-apply-methods-on-an-instance-which-is-part","errorCode":null,"errorMessage":"Calling apply methods on an instance which is part of a Prefab Asset is not supported.","messagePattern":"Calling apply methods on an instance which is part of a Prefab Asset is not supported\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":271,"sourceCode":"                ThrowExceptionIfInstanceIsPersistent(prefabInstanceObject);\n        }\n\n        static void ThrowExceptionIfAllPrefabInstanceObjectsAreInvalid(Object[] prefabInstanceObjects, bool isApply)\n        {\n            foreach (var obj in prefabInstanceObjects)\n            {\n                if (obj != null && (obj is GameObject || obj is Component) && IsPartOfPrefabInstance(obj) && !(isApply && EditorUtility.IsPersistent(obj)))\n                    return;\n            }\n\n            // Throw exception if all objects are invalid\n            throw new ArgumentException(\"Cannot apply or revert on any of the objects. Attempt with individual objects for details.\", nameof(prefabInstanceObjects));\n        }\n\n        static void ThrowExceptionIfInstanceIsPersistent(Object prefabInstanceObject)\n        {\n            if (EditorUtility.IsPersistent(prefabInstanceObject))\n                throw new ArgumentException(\"Calling apply methods on an instance which is part of a Prefab Asset is not supported.\", nameof(prefabInstanceObject));\n        }\n\n        public static GameObject[] FindAllInstancesOfPrefab(GameObject prefabRoot)\n        {\n            return FindAllInstancesOfPrefab_internal(prefabRoot, SceneHandle.None);\n        }\n\n        public static GameObject[] FindAllInstancesOfPrefab(GameObject prefabRoot, Scene scene)\n        {\n            if (!scene.IsValid())\n            {\n                throw new ArgumentException(\"Input scene is not valid: Could not be found.\");\n            }\n\n            return FindAllInstancesOfPrefab_internal(prefabRoot, scene.handle);\n        }\n\n        public static void MergePrefabInstance(GameObject instanceRoot)","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L253-L289","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["For apply, operate on a scene instance of the prefab, not the asset.","To change the asset, edit it in Prefab Mode or modify and save via PrefabUtility.SaveAsPrefabAsset instead of apply.","Use revert (not apply) if you must operate on the asset directly."],"exampleFix":"// before\n// obj is a prefab asset selected in the Project window\nPrefabUtility.ApplyPrefabOverride(obj, path); // throws\n\n// after\n// Instantiate into a scene, apply, then optionally save\nvar instance = (GameObject)PrefabUtility.InstantiatePrefab(obj);\nPrefabUtility.ApplyPrefabOverride(instance, path);","handlingStrategy":"validation","validationCode":"if (isApply && UnityEditor.EditorUtility.IsPersistent(obj))\n{ Debug.LogWarning(\"Apply is not supported on prefab assets; use a scene instance.\"); return; }","typeGuard":"static bool CanApply(UnityEngine.Object o) =>\n    (o is GameObject || o is Component) && !UnityEditor.EditorUtility.IsPersistent(o);","tryCatchPattern":null,"preventionTips":["Run apply only on scene instances, never on prefab assets.","For asset changes, edit in Prefab Mode or use SaveAsPrefabAsset instead of apply.","Use revert (not apply) when you must operate on the asset directly."],"tags":["prefab","apply","persistent-asset","asset-vs-instance"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}