{"record":{"id":"e294f34f13720ff8","repo":"Unity-Technologies/UnityCsReference","slug":"can-t-apply-to-an-immutable-prefab","errorCode":null,"errorMessage":"Can't apply to an immutable Prefab","messagePattern":"Can't apply to an immutable Prefab","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2165,"sourceCode":"            if (action == InteractionMode.UserAction)\n            {\n                Undo.RecordCreatedObject(GetPrefabInstanceHandle(instanceRoot), actionName);\n            }\n\n            return assetRoot;\n        }\n\n        internal static void ApplyPrefabInstance(GameObject instance)\n        {\n            if (instance == null)\n                throw new ArgumentNullException(nameof(instance));\n\n            // Include model check even though models are also immutable, since we can give a more clear exception message.\n            if (IsPartOfModelPrefab(instance))\n                throw new ArgumentException(\"Can't apply to a Model Prefab\");\n\n            if (IsPartOfImmutablePrefab(instance))\n                throw new ArgumentException(\"Can't apply to an immutable Prefab\");\n\n            if (!IsPartOfNonAssetPrefabInstance(instance))\n                throw new ArgumentException(\"Provided GameObject is not a Prefab instance\");\n\n            var root = GetOutermostPrefabInstanceRoot(instance);\n            if (root != instance)\n                throw new ArgumentException(\"GameObject to save Prefab from must be a Prefab root\");\n\n            var assetObject = GetCorrespondingObjectFromSource(instance);\n            string path = AssetDatabase.GetAssetPath(assetObject);\n\n            SaveAsPrefabAssetArgumentCheck(instance, path, true);\n\n            Internal_CallPrefabInstanceApplying(instance);\n\n            ApplyPrefabInstance_Internal(instance);\n\n            Internal_CallPrefabInstanceApplied(instance);","sourceCodeStart":2147,"sourceCodeEnd":2183,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2147-L2183","documentation":"Thrown by ApplyPrefabInstance when the instance is part of an immutable Prefab (IsPartOfImmutablePrefab returns true). Immutable Prefabs (e.g. from packages or model imports) cannot receive applied overrides because their content is managed externally.","triggerScenarios":"Calling ApplyPrefabInstance on an instance of a Prefab asset marked immutable. This catches non-model immutable Prefabs (the model case is caught earlier with a more specific message).","commonSituations":"Trying to apply overrides to a Prefab imported from a package or a protected system asset. Developer confuses an editable variant with its immutable base.","solutions":["Apply the override to a Prefab Variant or a copy you own under Assets/, not to the immutable base.","Check IsPartOfImmutablePrefab(instance) before calling ApplyPrefabInstance and redirect if true.","If the immutability is unexpected, verify the asset's package origin and import settings."],"exampleFix":"// before\nPrefabUtility.ApplyPrefabInstance(immutableInstance);\n// after\nif (PrefabUtility.IsPartOfImmutablePrefab(instance))\n    Debug.LogWarning(\"Cannot apply to immutable prefab; create a variant.\");\nelse\n    PrefabUtility.ApplyPrefabInstance(instance);","handlingStrategy":"validation","validationCode":"if (PrefabUtility.IsPartOfImmutablePrefab(instance))\n{ Debug.LogWarning(\"Immutable prefab; create a variant instead.\"); return; }\nPrefabUtility.ApplyPrefabInstance(instance);","typeGuard":"static bool IsMutableApplyableInstance(GameObject go) =>\n    go != null &&\n    !PrefabUtility.IsPartOfImmutablePrefab(go) &&\n    PrefabUtility.IsPartOfNonAssetPrefabInstance(go);","tryCatchPattern":null,"preventionTips":["Check IsPartOfImmutablePrefab before applying overrides.","Use Prefab Variants for structured override of protected bases.","Document which Prefabs in your project are package-managed (immutable)."],"tags":["unity","prefab","immutable","apply"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}