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
- 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.
- Check PrefabUtility.IsPartOfImmutablePrefab(GetCorrespondingObjectFromSourceAtPath(obj, assetPath)) before applying and skip/redirect.
- 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
- Copy package-shipped prefabs into a writable Assets/ folder before applying overrides.
- Use Prefab Variants instead of editing read-only base prefabs.
- Filter out immutable prefabs before bulk apply operations.
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
- Can't save a Model Prefab
- Can't save an immutable Prefab
- Can't apply to a Model Prefab
- Can't apply to an immutable Prefab
- Could not find editor resource ${assetPath}
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/52a4145c298d39aa.
Report an issue: GitHub.