# SerializationWarning: ScriptableObject 'PlayerData' has version mismatch. Expected version 1, found version 2. Data may be lost.

- **ID:** `unity/scriptableobject-serialization-version-mismatch`
- **Domain:** unity
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 78%

## Root Cause

A ScriptableObject asset was serialized with a newer version of its class definition (e.g., added fields), but the current code expects an older version, causing deserialization mismatches.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Unity 2021.3.0f1 | active | — | — |
| Unity 2022.3.0f1 | active | — | — |
| Unity 2023.2.0f1 | active | — | — |
| Unity 2024.1.0b1 | active | — | — |

## Workarounds

1. **Implement custom serialization with versioning: Add a version field to the ScriptableObject and use OnBeforeSerialize/OnAfterDeserialize to handle migration. Example:
public int version = 1;
public void OnAfterDeserialize() {
    if (version < 2) {
        // migrate old data
        version = 2;
    }
}** (80% success)
   ```
   Implement custom serialization with versioning: Add a version field to the ScriptableObject and use OnBeforeSerialize/OnAfterDeserialize to handle migration. Example:
public int version = 1;
public void OnAfterDeserialize() {
    if (version < 2) {
        // migrate old data
        version = 2;
    }
}
   ```
2. **Use a custom Editor script to update all ScriptableObject assets to the latest version: Iterate through assets and call a migration method that sets default values for new fields.** (75% success)
   ```
   Use a custom Editor script to update all ScriptableObject assets to the latest version: Iterate through assets and call a migration method that sets default values for new fields.
   ```

## Dead Ends

- **Delete and recreate the ScriptableObject asset from scratch** — This loses all existing data and may not be feasible if data is critical; also does not fix the root mismatch. (90% fail)
- **Revert the script to the old version without the new fields** — This prevents using new features and may break other parts of the code that depend on the new fields. (75% fail)
