Unity-Technologies/UnityCsReference · error · ArgumentException
Saving Prefab to immutable folder is not allowed: '{path}'
Error message
Saving Prefab to immutable folder is not allowed: '{path}' What it means
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.
Source
Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:2057
{
if (String.IsNullOrEmpty(path))
throw new ArgumentNullException("path is null or empty");
if (!Paths.IsValidAssetPath(path, ".prefab"))
throw new ArgumentException("Given path is not valid: '" + path + "'");
if (Directory.Exists(path))
throw new ArgumentException("Overwriting a folder with an Asset is not allowed: '" + path + "'");
string directory = Path.GetDirectoryName(path);
// We allow relative paths outside the Assets folder so we do not throw if isValidAssetFolder is false
bool isRootFolder = false;
bool isImmutableFolder = false;
bool isValidAssetFolder = AssetDatabase.TryGetAssetFolderInfo(directory, out isRootFolder, out isImmutableFolder);
if (isValidAssetFolder && isImmutableFolder)
throw new ArgumentException("Saving Prefab to immutable folder is not allowed: '" + path + "'");
if (directory.Length > 0 && !Directory.Exists(directory))
throw new ArgumentException("Given path does not exist: '" + path + "'");
if (isValidAssetFolder)
{
string projectRelativePath = Path.IsPathRooted(path) ? FileUtil.GetProjectRelativePath(path) : path;
string prefabGUID = AssetDatabase.AssetPathToGUID(projectRelativePath);
if (!VerifyNestingFromScript(new GameObject[] { instanceRoot }, prefabGUID, PrefabUtility.GetPrefabInstanceHandle(instanceRoot)))
throw new ArgumentException("Cyclic nesting detected");
}
}
private static void SaveAsPrefabAssetArgumentCheck(GameObject instanceRoot, string path, bool connectToInstance)
{
if (instanceRoot == null)
throw new ArgumentNullException("Parameter root is null");
View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before PrefabUtility.SaveAsPrefabAsset(go, "Packages/com.unity.something/My.prefab"); // after PrefabUtility.SaveAsPrefabAsset(go, "Assets/Prefabs/My.prefab");
Defensive patterns
Strategy: validation
Validate before calling
bool IsWritableAssetFolder(string dir)
{
bool isRoot, isImmutable;
if (AssetDatabase.TryGetAssetFolderInfo(dir, out isRoot, out isImmutable))
return !isImmutable;
return true; // outside Assets, caller's responsibility
} Type guard
static bool IsSafePrefabDestination(string path)
{
string dir = Path.GetDirectoryName(path);
bool isRoot, isImmutable;
bool valid = AssetDatabase.TryGetAssetFolderInfo(dir, out isRoot, out isImmutable);
return !valid || !isImmutable;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Can't save an immutable Prefab
- Overwriting a folder with an Asset is not allowed: '{path}'
- Given path does not exist: '{path}'
- Can't connect a Prefab in the StreamingAssets folder to Game
- Scene path "{0}" contains invalid directory separators.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/c102a11dcad20744.
Report an issue: GitHub.