Unity-Technologies/UnityCsReference · error · InvalidOperationException

Mismatching Types: Cannot revert a parts of a SerializeRefer

Error message

Mismatching Types: Cannot revert a parts of a SerializeReference property since the Prefab instance is referencing a different type compared to the Prefab Asset.

You can revert the root of the serialized reference or the entire component.

What it means

Thrown (AutomatedAction) / dialog (UserAction) during revert of a SerializeReference field when the source property could not be found on the asset (sourceProperty == null), indicating a type mismatch between the instance's managed reference type and the asset's. The error reports 'Cannot revert a parts of a SerializeReference property ... referencing a different type'.

Source

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

                if (revertingNotPossible)
                {
                    title = L10n.Tr("Mismatching Objects");
                    errorMsg = L10n.Tr("Cannot revert a single SerializeReference field since the Prefab instance is referencing a new object compared to the Prefab Asset.\n\nThis means that the entire object is considered an override, cannot revert parts of it.\n\nYou can revert the root of the serialized reference or the entire component.");
                }
            }
            else
            {
                // Type mismatch:
                title = L10n.Tr("Mismatching Types");
                errorMsg = L10n.Tr("Cannot revert a parts of a SerializeReference property since the Prefab instance is referencing a different type compared to the Prefab Asset.\n\nYou can revert the root of the serialized reference or the entire component.");
            }

            bool warnUser = !string.IsNullOrEmpty(errorMsg);
            if (warnUser)
            {
                if (action == InteractionMode.AutomatedAction)
                {
                    throw new InvalidOperationException(title + ": " + errorMsg);
                }
                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))

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Revert the SerializeReference root or the whole component to resolve the type difference.
  2. Make the asset and instance reference the same managed type before a partial revert.
  3. Detect type mismatch (sourceProp == null) and fall back to component-level revert.

Example fix

// before
PrefabUtility.RevertPropertyOverride(instanceRoot, "ref.nested", InteractionMode.AutomatedAction);

// after
PrefabUtility.RevertObjectOverride(component, InteractionMode.AutomatedAction);
Defensive patterns

Strategy: validation

Validate before calling

var src = new SerializedObject(assetObj).FindProperty(path);
if (src == null) path = refRootPath; // type mismatch: revert whole field
PrefabUtility.RevertPropertyOverride(instanceRoot, path, action);

Type guard

static bool AssetHasRevertableType(SerializedProperty src)
    => src != null;

Try / catch

try { PrefabUtility.RevertPropertyOverride(root, subPath, action); }
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Mismatching Types"))
{ PrefabUtility.RevertObjectOverride(component, action); }

Prevention

When it happens

Trigger: Reverting a SerializeReference sub-field where the instance references a managed type absent at that path in the asset (e.g., instance uses subtype B, asset uses subtype A or null).

Common situations: Polymorphic SerializeReference systems where subtype shape diverges; reverting after the asset's referenced type was changed; reverting nested fields of a reference whose type only exists on the instance.

Related errors


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