{"record":{"id":"186e8a90e20ed759","repo":"Unity-Technologies/UnityCsReference","slug":"can-t-save-an-immutable-prefab","errorCode":null,"errorMessage":"Can't save an immutable Prefab","messagePattern":"Can't save an immutable Prefab","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2025,"sourceCode":"        }\n\n        public static GameObject SavePrefabAsset(GameObject asset)\n        {\n            bool savedSuccesfully;\n            return SavePrefabAsset(asset, out savedSuccesfully);\n        }\n\n        public static GameObject SavePrefabAsset(GameObject asset, out bool savedSuccessfully)\n        {\n            if (asset == null)\n                throw new ArgumentNullException(\"Parameter prefabAssetGameObject is null\");\n\n            // Include model check even though models are also immutable, since we can give a more clear exception message.\n            if (IsPartOfModelPrefab(asset))\n                throw new ArgumentException(\"Can't save a Model Prefab\");\n\n            if (IsPartOfImmutablePrefab(asset))\n                throw new ArgumentException(\"Can't save an immutable Prefab\");\n\n            string path = AssetDatabase.GetAssetPath(asset);\n            if (String.IsNullOrEmpty(path))\n                throw new ArgumentException(\"Can't save a Prefab instance\");\n\n            var root = asset.transform.root.gameObject;\n            if (root != asset)\n                throw new ArgumentException(\"GameObject to save Prefab from must be a Prefab root\");\n\n            return SavePrefabAsset_Internal(root, out savedSuccessfully);\n        }\n\n        internal static void ValidatePath(GameObject instanceRoot, string path)\n        {\n            if (String.IsNullOrEmpty(path))\n                throw new ArgumentNullException(\"path is null or empty\");\n\n            if (!Paths.IsValidAssetPath(path, \".prefab\"))","sourceCodeStart":2007,"sourceCodeEnd":2043,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2007-L2043","documentation":"SavePrefabAsset throws for immutable prefabs — prefabs that live in a read-only location such as an imported package. Immutable prefabs cannot be modified, so saving is rejected. This is the generic immutability check that runs after the model-specific check (594).","triggerScenarios":"Calling SavePrefabAsset on a prefab asset that resides in an immutable/package folder (IsPartOfImmutablePrefab returns true).","commonSituations":"Editing a prefab that ships inside a Unity package (Packages/ or a read-only location); trying to save changes to a prefab from an imported asset store package.","solutions":["Override the prefab into a writable copy under Assets/, or create a prefab variant.","Move/duplicate the prefab into the project's Assets folder before editing.","Filter with !PrefabUtility.IsPartOfImmutablePrefab(asset) before attempting to save."],"exampleFix":"// before\nPrefabUtility.SavePrefabAsset(pkgPrefabRoot);\n\n// after\nif (PrefabUtility.IsPartOfImmutablePrefab(pkgPrefabRoot))\n    PrefabUtility.SaveAsPrefabAsset(pkgPrefabRoot, \"Assets/LocalCopy.prefab\");\nelse\n    PrefabUtility.SavePrefabAsset(pkgPrefabRoot);","handlingStrategy":"validation","validationCode":"if (PrefabUtility.IsPartOfImmutablePrefab(asset))\n{\n    // copy into Assets/ first\n    return;\n}","typeGuard":"static bool IsWritablePrefab(GameObject asset) =>\n    asset != null && !PrefabUtility.IsPartOfImmutablePrefab(asset);","tryCatchPattern":null,"preventionTips":["Filter out immutable/package prefabs with IsPartOfImmutablePrefab before saving.","Duplicate package prefabs into Assets/ before editing.","Use prefab variants to override read-only package prefabs."],"tags":["prefab","unity","immutable","package"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}