{"record":{"id":"a9b378da779c27fa","repo":"Unity-Technologies/UnityCsReference","slug":"mismatching-objects-cannot-revert-a-single-serial","errorCode":null,"errorMessage":"Mismatching Objects: 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.","messagePattern":"Mismatching Objects: 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\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":1072,"sourceCode":"                if (revertingNotPossible)\n                {\n                    title = L10n.Tr(\"Mismatching Objects\");\n                    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.\");\n                }\n            }\n            else\n            {\n                // Type mismatch:\n                title = L10n.Tr(\"Mismatching Types\");\n                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.\");\n            }\n\n            bool warnUser = !string.IsNullOrEmpty(errorMsg);\n            if (warnUser)\n            {\n                if (action == InteractionMode.AutomatedAction)\n                {\n                    throw new InvalidOperationException(title + \": \" + errorMsg);\n                }\n                else if (action == InteractionMode.UserAction)\n                {\n                    EditorUtility.DisplayDialog(title, errorMsg, L10n.Tr(\"OK\"));\n                }\n            }\n\n            return warnUser;\n        }\n\n        public static void ApplyObjectOverride(Object instanceComponentOrGameObject, string assetPath, InteractionMode action)\n        {\n            DateTime startTime = DateTime.UtcNow;\n\n            ThrowExceptionIfNotValidPrefabInstanceObject(instanceComponentOrGameObject, true);\n\n            var obj = GetCorrespondingObjectFromSourceAtPath(instanceComponentOrGameObject, assetPath);\n            if (IsPartOfImmutablePrefab(obj))","sourceCodeStart":1054,"sourceCodeEnd":1090,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L1054-L1090","documentation":"Thrown (AutomatedAction) / dialog (UserAction) during revert of a SerializeReference field when the instance's managedReferencePropertyPath differs from the asset's (object mismatch). Because the entire managed object is treated as an override, Unity cannot revert only part of it; you must revert the reference root or the whole component.","triggerScenarios":"Reverting a single SerializeReference sub-field via automation where the instance references a different managed object than the asset (revertingNotPossible == true).","commonSituations":"Polymorphic managed-reference fields where the instance swapped the referenced object; reverting after assigning a new managed reference instance; reverting nested fields of an inventory/stat system.","solutions":["Revert the SerializeReference root field instead of a sub-field.","Revert the entire component to restore the asset's reference identity.","Pre-check instanceProperty.managedReferencePropertyPath == sourceProperty.managedReferencePropertyPath before attempting a sub-field revert."],"exampleFix":"// before\nPrefabUtility.RevertPropertyOverride(instanceRoot, \"ref.subField\", InteractionMode.AutomatedAction);\n\n// after\nPrefabUtility.RevertPropertyOverride(instanceRoot, \"ref\", InteractionMode.AutomatedAction);","handlingStrategy":"validation","validationCode":"var inst = new SerializedObject(instanceObj).FindProperty(path);\nvar src = new SerializedObject(assetObj).FindProperty(path);\nif (inst != null && src != null &&\n    inst.managedReferencePropertyPath != src.managedReferencePropertyPath)\n    path = refRootPath; // revert at root instead\nPrefabUtility.RevertPropertyOverride(instanceRoot, path, action);","typeGuard":"static bool CanRevertSubField(SerializedProperty inst, SerializedProperty src)\n    => inst != null && src != null &&\n       inst.managedReferencePropertyPath == src.managedReferencePropertyPath;","tryCatchPattern":"try { PrefabUtility.RevertPropertyOverride(root, subPath, action); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Mismatching Objects\"))\n{ PrefabUtility.RevertPropertyOverride(root, refRootPath, action); }","preventionTips":["Revert the SerializeReference root when the instance references a different managed object.","Compare managedReferencePropertyPath before attempting a sub-field revert.","For polymorphic references, default to component-level revert."],"tags":["prefab","serializereference","override","revert"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}