{
  "id": "unity/scriptableobject-serialization-version-mismatch",
  "signature": "SerializationWarning: ScriptableObject 'PlayerData' has version mismatch. Expected version 1, found version 2. Data may be lost.",
  "signature_zh": "序列化警告：ScriptableObject 'PlayerData' 版本不匹配。预期版本 1，找到版本 2。数据可能丢失。",
  "regex": "SerializationWarning: ScriptableObject '.*' has version mismatch\\. Expected version \\d+, found version \\d+\\.",
  "domain": "unity",
  "category": "data_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "ScriptableObject 资源使用较新版本的类定义（例如添加了字段）序列化，但当前代码期望旧版本，导致反序列化不匹配。",
  "versions": [
    {
      "version": "Unity 2021.3.0f1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Unity 2022.3.0f1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Unity 2023.2.0f1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Unity 2024.1.0b1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Delete and recreate the ScriptableObject asset from scratch",
      "why_fails": "This loses all existing data and may not be feasible if data is critical; also does not fix the root mismatch.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Revert the script to the old version without the new fields",
      "why_fails": "This prevents using new features and may break other parts of the code that depend on the new fields.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Implement custom serialization with versioning: Add a version field to the ScriptableObject and use OnBeforeSerialize/OnAfterDeserialize to handle migration. Example:\npublic int version = 1;\npublic void OnAfterDeserialize() {\n    if (version < 2) {\n        // migrate old data\n        version = 2;\n    }\n}",
      "success_rate": 0.8,
      "how": "Implement custom serialization with versioning: Add a version field to the ScriptableObject and use OnBeforeSerialize/OnAfterDeserialize to handle migration. Example:\npublic int version = 1;\npublic void OnAfterDeserialize() {\n    if (version < 2) {\n        // migrate old data\n        version = 2;\n    }\n}",
      "condition": "",
      "sources": []
    },
    {
      "action": "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.",
      "success_rate": 0.75,
      "how": "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.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Implement custom serialization with versioning: Add a version field to the ScriptableObject and use OnBeforeSerialize/OnAfterDeserialize to handle migration. Example:\npublic int version = 1;\npublic void OnAfterDeserialize() {\n    if (version < 2) {\n        // migrate old data\n        version = 2;\n    }\n}",
    "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."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.unity3d.com/ScriptReference/Serialization.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.78,
  "resolvable": "partial",
  "first_seen": "2023-10-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}