Unity-Technologies/UnityCsReference · error · InvalidOperationException

Mismatching Objects: Cannot apply SerializeReference field s

Error message

Mismatching Objects: Cannot apply SerializeReference field since the Prefab instance is referencing a new object compared to the Prefab Asset.

This means that the changes from the Prefab Asset cannot be merged back to the Prefab instance.

You can apply the root of the field or the entire component(instance property {instanceProperty.managedReferencePropertyPath}, asset property {sourceProperty.managedReferencePropertyPath})

What it means

Thrown (AutomatedAction) or shown as a dialog (UserAction) when applying a SerializeReference sub-field whose managedReferencePropertyPath on the instance differs from the asset. The instance is referencing a different managed object than the asset, so Unity cannot merge the asset's state back — only the whole field or whole component can be applied. The exception interpolates both property paths for diagnostics.

Source

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

        }

        static bool WarnIfApplyingManagedReferenceFieldIsNotPossible(SerializedProperty instanceProperty, SerializedProperty sourceProperty, InteractionMode action)
        {
            bool isReferencingAManagedReferenceField = instanceProperty.isReferencingAManagedReferenceField;
            if (!isReferencingAManagedReferenceField)
                return false;

            if (sourceProperty != null)
            {
                // Even if we find the propertyPath on the source object we also need to validate if this is a managed reference to the correct source object, except when
                // applying an entire object because then entire state is transfered to the asset and can merged back to the instance so here we don't show the dialog.
                bool applyingNotPossible = instanceProperty.managedReferencePropertyPath != sourceProperty.managedReferencePropertyPath;
                if (applyingNotPossible)
                {
                    string title = L10n.Tr("Mismatching Objects");
                    string errorMsg = L10n.Tr("Cannot apply SerializeReference field since the Prefab instance is referencing a new object compared to the Prefab Asset.\n\nThis means that the changes from the Prefab Asset cannot be merged back to the Prefab instance.\n\nYou can apply the root of the field or the entire component");
                    if (action == InteractionMode.AutomatedAction)
                        throw new InvalidOperationException(title + ": " + errorMsg + $"(instance property { instanceProperty.managedReferencePropertyPath}, asset property { sourceProperty.managedReferencePropertyPath})");
                    else
                        EditorUtility.DisplayDialog(
                            title,
                            errorMsg,
                            L10n.Tr("OK"));
                    return true;
                }
            }
            else
            {
                // Special handling for managed references.
                // If we have a valid managedReferencePropertyPath then the types must be different since we could not find the
                // propertyPath on the Prefab Asset, tell the user that this is not supported.
                if (!string.IsNullOrEmpty(instanceProperty.managedReferencePropertyPath))
                {
                    string title = L10n.Tr("Mismatching Types");
                    string errorMsg = L10n.Tr("Cannot apply a SerializeReference sub field when the type from the Prefab instance is different from the Prefab Asset.\n\nYou can apply the root of the field or the entire component");
                    if (action == InteractionMode.AutomatedAction)

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Apply the entire SerializeReference root field instead of a sub-field (use the property's root path).
  2. Apply the whole component override rather than a single nested reference property.
  3. Before applying, check instanceProperty.managedReferencePropertyPath == sourceProperty.managedReferencePropertyPath and only apply when they match.

Example fix

// before
PrefabUtility.ApplyPropertyOverride(instanceRoot, "myField.nested.subValue", assetPath);

// after
// apply at the SerializeReference root instead
PrefabUtility.ApplyPropertyOverride(instanceRoot, "myField", assetPath);
Defensive patterns

Strategy: validation

Validate before calling

// Compare managed reference identity before applying a sub-field
var inst = new SerializedObject(instanceObj).FindProperty(path);
var src = new SerializedObject(assetObj).FindProperty(path);
if (inst != null && src != null &&
    inst.managedReferencePropertyPath == src.managedReferencePropertyPath)
    PrefabUtility.ApplyPropertyOverride(instanceRoot, path, assetPath);

Type guard

static bool CanApplySubField(SerializedProperty inst, SerializedProperty src)
    => inst != null && src != null &&
       inst.managedReferencePropertyPath == src.managedReferencePropertyPath;

Try / catch

try { PrefabUtility.ApplyPropertyOverride(root, subPath, assetPath); }
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Mismatching Objects"))
{ PrefabUtility.ApplyPropertyOverride(root, refRootPath, assetPath); }

Prevention

When it happens

Trigger: Selecting a nested SerializeReference sub-field on a prefab instance whose polymorphic object was swapped (different managed reference identity) relative to the prefab asset, then invoking Apply override via automation.

Common situations: Polymorphic [SerializeReference] fields where the instance assigned a different subtype instance than the asset; inventory/skill systems using managed references; applying a single nested property after a reference swap.

Related errors


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