Unity-Technologies/UnityCsReference · error · ArgumentException

Can't apply to an immutable Prefab

Error message

Can't apply to an immutable Prefab

What it means

Thrown by ApplyPrefabInstance when the instance is part of an immutable Prefab (IsPartOfImmutablePrefab returns true). Immutable Prefabs (e.g. from packages or model imports) cannot receive applied overrides because their content is managed externally.

Source

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

            if (action == InteractionMode.UserAction)
            {
                Undo.RecordCreatedObject(GetPrefabInstanceHandle(instanceRoot), actionName);
            }

            return assetRoot;
        }

        internal static void ApplyPrefabInstance(GameObject instance)
        {
            if (instance == null)
                throw new ArgumentNullException(nameof(instance));

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

            if (IsPartOfImmutablePrefab(instance))
                throw new ArgumentException("Can't apply to an immutable Prefab");

            if (!IsPartOfNonAssetPrefabInstance(instance))
                throw new ArgumentException("Provided GameObject is not a Prefab instance");

            var root = GetOutermostPrefabInstanceRoot(instance);
            if (root != instance)
                throw new ArgumentException("GameObject to save Prefab from must be a Prefab root");

            var assetObject = GetCorrespondingObjectFromSource(instance);
            string path = AssetDatabase.GetAssetPath(assetObject);

            SaveAsPrefabAssetArgumentCheck(instance, path, true);

            Internal_CallPrefabInstanceApplying(instance);

            ApplyPrefabInstance_Internal(instance);

            Internal_CallPrefabInstanceApplied(instance);

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Apply the override to a Prefab Variant or a copy you own under Assets/, not to the immutable base.
  2. Check IsPartOfImmutablePrefab(instance) before calling ApplyPrefabInstance and redirect if true.
  3. If the immutability is unexpected, verify the asset's package origin and import settings.

Example fix

// before
PrefabUtility.ApplyPrefabInstance(immutableInstance);
// after
if (PrefabUtility.IsPartOfImmutablePrefab(instance))
    Debug.LogWarning("Cannot apply to immutable prefab; create a variant.");
else
    PrefabUtility.ApplyPrefabInstance(instance);
Defensive patterns

Strategy: validation

Validate before calling

if (PrefabUtility.IsPartOfImmutablePrefab(instance))
{ Debug.LogWarning("Immutable prefab; create a variant instead."); return; }
PrefabUtility.ApplyPrefabInstance(instance);

Type guard

static bool IsMutableApplyableInstance(GameObject go) =>
    go != null &&
    !PrefabUtility.IsPartOfImmutablePrefab(go) &&
    PrefabUtility.IsPartOfNonAssetPrefabInstance(go);

Prevention

When it happens

Trigger: Calling ApplyPrefabInstance on an instance of a Prefab asset marked immutable. This catches non-model immutable Prefabs (the model case is caught earlier with a more specific message).

Common situations: Trying to apply overrides to a Prefab imported from a package or a protected system asset. Developer confuses an editable variant with its immutable base.

Related errors


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