{"record":{"id":"69d3e4cbe354829d","repo":"Unity-Technologies/UnityCsReference","slug":"mismatching-types-cannot-apply-a-serializereferen","errorCode":null,"errorMessage":"Mismatching Types: 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","messagePattern":"Mismatching Types: 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","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Prefabs/PrefabUtility.cs","lineNumber":1024,"sourceCode":"                    else\n                        EditorUtility.DisplayDialog(\n                            title,\n                            errorMsg,\n                            L10n.Tr(\"OK\"));\n                    return true;\n                }\n            }\n            else\n            {\n                // Special handling for managed references.\n                // If we have a valid managedReferencePropertyPath then the types must be different since we could not find the\n                // propertyPath on the Prefab Asset, tell the user that this is not supported.\n                if (!string.IsNullOrEmpty(instanceProperty.managedReferencePropertyPath))\n                {\n                    string title = L10n.Tr(\"Mismatching Types\");\n                    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\");\n                    if (action == InteractionMode.AutomatedAction)\n                        throw new InvalidOperationException(title + \": \" + errorMsg);\n                    else\n                        EditorUtility.DisplayDialog(\n                            title,\n                            errorMsg,\n                            L10n.Tr(\"OK\"));\n\n                    return true;\n                }\n            }\n\n            return false;\n        }\n\n        static bool WarnIfRevertingManagedReferenceIsNotPossible(SerializedProperty instanceProperty, InteractionMode action)\n        {\n            if (!instanceProperty.isReferencingAManagedReferenceField)\n                return false;\n","sourceCodeStart":1006,"sourceCodeEnd":1042,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Prefabs/PrefabUtility.cs#L1006-L1042","documentation":"Thrown (AutomatedAction) / dialog (UserAction) when applying a SerializeReference sub-field whose propertyPath cannot be found on the prefab asset (sourceProperty is null) while the instance has a non-empty managedReferencePropertyPath. That means the instance's referenced managed type differs from the asset's, so Unity cannot locate the corresponding sub-field to merge.","triggerScenarios":"Applying a SerializeReference sub-field where the instance references a managed type that the asset does not have at that path (e.g., instance swapped to a subtype with extra fields, or the asset's reference is null/different type).","commonSituations":"Polymorphic SerializeReference hierarchies where subtype shape differs between instance and asset; applying after changing the referenced type; data-driven systems where the instance uses a richer subtype than the prefab base.","solutions":["Apply at the SerializeReference root or the entire component so the full type state transfers.","Align the managed reference types between instance and asset before applying the sub-field.","Detect via: sourceProp == null || instanceProp.managedReferencePropertyPath differs from asset, then fall back to component-level apply."],"exampleFix":"// before\nPrefabUtility.ApplyPropertyOverride(instanceRoot, \"ref.field.x\", assetPath);\n\n// after\n// apply the whole SerializeReference field, not a sub-property\nPrefabUtility.ApplyPropertyOverride(instanceRoot, \"ref\", assetPath);","handlingStrategy":"validation","validationCode":"var src = new SerializedObject(assetObj).FindProperty(path);\nif (src == null) { /* type mismatch: apply whole field instead */ path = refRootPath; }\nPrefabUtility.ApplyPropertyOverride(instanceRoot, path, assetPath);","typeGuard":"static bool AssetHasMatchingType(SerializedProperty src, SerializedProperty inst)\n    => src != null && !string.IsNullOrEmpty(inst.managedReferencePropertyPath);","tryCatchPattern":"try { PrefabUtility.ApplyPropertyOverride(root, subPath, assetPath); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Mismatching Types\"))\n{ PrefabUtility.ApplyPropertyOverride(root, refRootPath, assetPath); }","preventionTips":["When the asset lacks the propertyPath, apply the whole SerializeReference field or component.","Align managed reference types between instance and asset before partial apply.","Treat sourceProperty == null as a signal to fall back to component-level apply."],"tags":["prefab","serializereference","override","type-mismatch"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}