{"record":{"id":"983a103b682fab0d","repo":"Unity-Technologies/UnityCsReference","slug":"mismatching-types-cannot-revert-a-parts-of-a-seri","errorCode":null,"errorMessage":"Mismatching Types: 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.","messagePattern":"Mismatching Types: 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\\.","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 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'.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Revert the SerializeReference root or the whole component to resolve the type difference.","Make the asset and instance reference the same managed type before a partial revert.","Detect type mismatch (sourceProp == null) and fall back to component-level revert."],"exampleFix":"// before\nPrefabUtility.RevertPropertyOverride(instanceRoot, \"ref.nested\", InteractionMode.AutomatedAction);\n\n// after\nPrefabUtility.RevertObjectOverride(component, InteractionMode.AutomatedAction);","handlingStrategy":"validation","validationCode":"var src = new SerializedObject(assetObj).FindProperty(path);\nif (src == null) path = refRootPath; // type mismatch: revert whole field\nPrefabUtility.RevertPropertyOverride(instanceRoot, path, action);","typeGuard":"static bool AssetHasRevertableType(SerializedProperty src)\n    => src != null;","tryCatchPattern":"try { PrefabUtility.RevertPropertyOverride(root, subPath, action); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Mismatching Types\"))\n{ PrefabUtility.RevertObjectOverride(component, action); }","preventionTips":["When the asset cannot find the propertyPath (type differs), revert the whole field or component.","Match managed reference types between instance and asset before partial revert.","Treat sourceProperty == null as a signal to escalate to component-level revert."],"tags":["prefab","serializereference","override","type-mismatch","revert"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}