Unity-Technologies/UnityCsReference · error · ArgumentException

Cannot applyt to immutable prefab: {assetPath}

Error message

Cannot applyt to immutable prefab: {assetPath}

What it means

Thrown by ApplyObjectOverride when GetCorrespondingObjectFromSourceAtPath resolves the asset-side object and PrefabUtility.IsPartOfImmutablePrefab(obj) returns true. Immutable prefabs live in read-only locations (the package cache, built-in packages, or read-only assets) and cannot be written to, so applying an override back to them is rejected. Note the message contains a typo ('applyt') as shipped.

Source

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

                }
                else if (action == InteractionMode.UserAction)
                {
                    EditorUtility.DisplayDialog(title, errorMsg, L10n.Tr("OK"));
                }
            }

            return warnUser;
        }

        public static void ApplyObjectOverride(Object instanceComponentOrGameObject, string assetPath, InteractionMode action)
        {
            DateTime startTime = DateTime.UtcNow;

            ThrowExceptionIfNotValidPrefabInstanceObject(instanceComponentOrGameObject, true);

            var obj = GetCorrespondingObjectFromSourceAtPath(instanceComponentOrGameObject, assetPath);
            if (IsPartOfImmutablePrefab(obj))
                throw new ArgumentException($"Cannot applyt to immutable prefab: {assetPath}");

            if (WarnIfInAnimationMode(OverrideOperation.Apply, action))
                return;

            if (action == InteractionMode.UserAction)
            {
                ApplyObjectOverride(instanceComponentOrGameObject, assetPath);

                Component instanceComponent = instanceComponentOrGameObject as Component;
                if (instanceComponent != null)
                {
                    Component coupledComponent = instanceComponent.GetCoupledComponent();
                    if (coupledComponent != null)
                        ApplyObjectOverride(coupledComponent, assetPath);
                }
            }
            else
            {

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Make the prefab writable: copy the prefab asset out of Packages/<pkg> into Assets/ and repoint instances, or use a Prefab Variant instead of applying into the base.
  2. Check PrefabUtility.IsPartOfImmutablePrefab(GetCorrespondingObjectFromSourceAtPath(obj, assetPath)) before applying and skip/redirect.
  3. Ensure the target prefab asset lives under a writable Assets/ folder, not the read-only package cache.

Example fix

// before
PrefabUtility.ApplyObjectOverride(obj, assetPath, InteractionMode.AutomatedAction);

// after
var src = PrefabUtility.GetCorrespondingObjectFromSourceAtPath(obj, assetPath);
if (src != null && PrefabUtility.IsPartOfImmutablePrefab(src))
    Debug.LogWarning($"Skipping immutable prefab at {assetPath}");
else
    PrefabUtility.ApplyObjectOverride(obj, assetPath, InteractionMode.AutomatedAction);
Defensive patterns

Strategy: validation

Validate before calling

var src = PrefabUtility.GetCorrespondingObjectFromSourceAtPath(obj, assetPath);
if (src != null && PrefabUtility.IsPartOfImmutablePrefab(src))
{
    Debug.LogWarning($"Cannot apply to immutable prefab: {assetPath}");
    return;
}
PrefabUtility.ApplyObjectOverride(obj, assetPath, action);

Type guard

static bool IsWritablePrefab(Object src)
    => src == null || !PrefabUtility.IsPartOfImmutablePrefab(src);

Try / catch

try { PrefabUtility.ApplyObjectOverride(obj, assetPath, action); }
catch (ArgumentException ex) when (ex.Message.Contains("immutable prefab"))
{ Debug.LogWarning($"Skipped immutable prefab: {assetPath}"); }

Prevention

When it happens

Trigger: Calling PrefabUtility.ApplyObjectOverride on an instance whose source prefab asset is inside the Packages folder cache (e.g. com.unity.*), a built-in module prefab, or any asset marked read-only; applying overrides from a prefab variant of an immutable base.

Common situations: Customizing prefabs sourced from an imported asset package without first copying them into Assets/; editor tools that bulk-apply overrides including instances of package-shipped prefabs; workflows that forget to make prefabs writable first.

Related errors


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