{"record":{"id":"c102a11dcad20744","repo":"Unity-Technologies/UnityCsReference","slug":"saving-prefab-to-immutable-folder-is-not-allowed","errorCode":null,"errorMessage":"Saving Prefab to immutable folder is not allowed: '{path}'","messagePattern":"Saving Prefab to immutable folder is not allowed: '(.+?)'","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":2057,"sourceCode":"        {\n            if (String.IsNullOrEmpty(path))\n                throw new ArgumentNullException(\"path is null or empty\");\n\n            if (!Paths.IsValidAssetPath(path, \".prefab\"))\n                throw new ArgumentException(\"Given path is not valid: '\" + path + \"'\");\n\n            if (Directory.Exists(path))\n                throw new ArgumentException(\"Overwriting a folder with an Asset is not allowed: '\" + path + \"'\");\n\n            string directory = Path.GetDirectoryName(path);\n\n            // We allow relative paths outside the Assets folder so we do not throw if isValidAssetFolder is false\n            bool isRootFolder = false;\n            bool isImmutableFolder = false;\n            bool isValidAssetFolder = AssetDatabase.TryGetAssetFolderInfo(directory, out isRootFolder, out isImmutableFolder);\n\n            if (isValidAssetFolder && isImmutableFolder)\n                throw new ArgumentException(\"Saving Prefab to immutable folder is not allowed: '\" + path + \"'\");\n\n            if (directory.Length > 0 && !Directory.Exists(directory))\n                throw new ArgumentException(\"Given path does not exist: '\" + path + \"'\");\n\n            if (isValidAssetFolder)\n            {\n                string projectRelativePath = Path.IsPathRooted(path) ? FileUtil.GetProjectRelativePath(path) : path;\n                string prefabGUID = AssetDatabase.AssetPathToGUID(projectRelativePath);\n                if (!VerifyNestingFromScript(new GameObject[] { instanceRoot }, prefabGUID, PrefabUtility.GetPrefabInstanceHandle(instanceRoot)))\n                    throw new ArgumentException(\"Cyclic nesting detected\");\n            }\n        }\n\n        private static void SaveAsPrefabAssetArgumentCheck(GameObject instanceRoot, string path, bool connectToInstance)\n        {\n            if (instanceRoot == null)\n                throw new ArgumentNullException(\"Parameter root is null\");\n","sourceCodeStart":2039,"sourceCodeEnd":2075,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L2039-L2075","documentation":"Thrown by ValidatePath when AssetDatabase.TryGetAssetFolderInfo reports the destination directory as an immutable folder (e.g. a built-in package folder or read-only system folder). Unity blocks writes to immutable folders to preserve package integrity and prevent accidental corruption of shipped content.","triggerScenarios":"Saving a Prefab into a path under a package marked immutable (e.g. \"Packages/com.unity.somepackage/...\" or \"Library/\"). The directory resolves as valid and isImmutable=true via TryGetAssetFolderInfo.","commonSituations":"Attempting to save a Prefab asset into a read-only imported package's folder. Developer confuses a global-package path (immutable) with an embedded local package path. After upgrading a package, its folder may become immutable.","solutions":["Save the Prefab to a writable location under Assets/ (e.g. \"Assets/Prefabs/MyPrefab.prefab\").","If you need it in a package, use a local embedded package under Packages/ that you own, not a registry-imported immutable one.","Verify the target folder's mutability with AssetDatabase.TryGetAssetFolderInfo before saving."],"exampleFix":"// before\nPrefabUtility.SaveAsPrefabAsset(go, \"Packages/com.unity.something/My.prefab\");\n// after\nPrefabUtility.SaveAsPrefabAsset(go, \"Assets/Prefabs/My.prefab\");","handlingStrategy":"validation","validationCode":"bool IsWritableAssetFolder(string dir)\n{\n    bool isRoot, isImmutable;\n    if (AssetDatabase.TryGetAssetFolderInfo(dir, out isRoot, out isImmutable))\n        return !isImmutable;\n    return true; // outside Assets, caller's responsibility\n}","typeGuard":"static bool IsSafePrefabDestination(string path)\n{\n    string dir = Path.GetDirectoryName(path);\n    bool isRoot, isImmutable;\n    bool valid = AssetDatabase.TryGetAssetFolderInfo(dir, out isRoot, out isImmutable);\n    return !valid || !isImmutable;\n}","tryCatchPattern":null,"preventionTips":["Save Prefabs only under Assets/ directories you own.","Treat any Packages/ registry path as read-only by default.","Validate folder mutability before batch save operations."],"tags":["unity","prefab","path-validation","immutable-folder","package"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}