Unity-Technologies/UnityCsReference · error · InvalidOperationException
Mismatching Types: Cannot apply a SerializeReference sub fie
Error message
Mismatching Types: Cannot apply a SerializeReference sub field when the type from the Prefab instance is different from the Prefab Asset. You can apply the root of the field or the entire component
What it means
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.
Source
Thrown at Editor/Mono/Prefabs/PrefabUtility.cs:1024
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)
throw new InvalidOperationException(title + ": " + errorMsg);
else
EditorUtility.DisplayDialog(
title,
errorMsg,
L10n.Tr("OK"));
return true;
}
}
return false;
}
static bool WarnIfRevertingManagedReferenceIsNotPossible(SerializedProperty instanceProperty, InteractionMode action)
{
if (!instanceProperty.isReferencingAManagedReferenceField)
return false;
View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before PrefabUtility.ApplyPropertyOverride(instanceRoot, "ref.field.x", assetPath); // after // apply the whole SerializeReference field, not a sub-property PrefabUtility.ApplyPropertyOverride(instanceRoot, "ref", assetPath);
Defensive patterns
Strategy: validation
Validate before calling
var src = new SerializedObject(assetObj).FindProperty(path);
if (src == null) { /* type mismatch: apply whole field instead */ path = refRootPath; }
PrefabUtility.ApplyPropertyOverride(instanceRoot, path, assetPath); Type guard
static bool AssetHasMatchingType(SerializedProperty src, SerializedProperty inst)
=> src != null && !string.IsNullOrEmpty(inst.managedReferencePropertyPath); Try / catch
try { PrefabUtility.ApplyPropertyOverride(root, subPath, assetPath); }
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Mismatching Types"))
{ PrefabUtility.ApplyPropertyOverride(root, refRootPath, assetPath); } Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Mismatching Types: Cannot revert a parts of a SerializeRefer
- Mismatching Objects: Cannot apply SerializeReference field s
- Mismatching Objects: Cannot revert a single SerializeReferen
- Input array contains objects which are not part of a Prefab
- Cannot apply added component. Component is not an added comp
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/69d3e4cbe354829d.
Report an issue: GitHub.