Unity-Technologies/UnityCsReference · error · ArgumentException

Can't save an immutable Prefab

Error message

Can't save an immutable Prefab

What it means

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).

Source

Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:2025

        }

        public static GameObject SavePrefabAsset(GameObject asset)
        {
            bool savedSuccesfully;
            return SavePrefabAsset(asset, out savedSuccesfully);
        }

        public static GameObject SavePrefabAsset(GameObject asset, out bool savedSuccessfully)
        {
            if (asset == null)
                throw new ArgumentNullException("Parameter prefabAssetGameObject is null");

            // Include model check even though models are also immutable, since we can give a more clear exception message.
            if (IsPartOfModelPrefab(asset))
                throw new ArgumentException("Can't save a Model Prefab");

            if (IsPartOfImmutablePrefab(asset))
                throw new ArgumentException("Can't save an immutable Prefab");

            string path = AssetDatabase.GetAssetPath(asset);
            if (String.IsNullOrEmpty(path))
                throw new ArgumentException("Can't save a Prefab instance");

            var root = asset.transform.root.gameObject;
            if (root != asset)
                throw new ArgumentException("GameObject to save Prefab from must be a Prefab root");

            return SavePrefabAsset_Internal(root, out savedSuccessfully);
        }

        internal static void ValidatePath(GameObject instanceRoot, string path)
        {
            if (String.IsNullOrEmpty(path))
                throw new ArgumentNullException("path is null or empty");

            if (!Paths.IsValidAssetPath(path, ".prefab"))

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Override the prefab into a writable copy under Assets/, or create a prefab variant.
  2. Move/duplicate the prefab into the project's Assets folder before editing.
  3. Filter with !PrefabUtility.IsPartOfImmutablePrefab(asset) before attempting to save.

Example fix

// before
PrefabUtility.SavePrefabAsset(pkgPrefabRoot);

// after
if (PrefabUtility.IsPartOfImmutablePrefab(pkgPrefabRoot))
    PrefabUtility.SaveAsPrefabAsset(pkgPrefabRoot, "Assets/LocalCopy.prefab");
else
    PrefabUtility.SavePrefabAsset(pkgPrefabRoot);
Defensive patterns

Strategy: validation

Validate before calling

if (PrefabUtility.IsPartOfImmutablePrefab(asset))
{
    // copy into Assets/ first
    return;
}

Type guard

static bool IsWritablePrefab(GameObject asset) =>
    asset != null && !PrefabUtility.IsPartOfImmutablePrefab(asset);

Prevention

When it happens

Trigger: Calling SavePrefabAsset on a prefab asset that resides in an immutable/package folder (IsPartOfImmutablePrefab returns true).

Common situations: 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.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/186e8a90e20ed759. Report an issue: GitHub.