{
  "id": "unity/argumentoutofrangeexception-animationcurve-key",
  "signature": "ArgumentOutOfRangeException: Index is out of range. Must be non-negative and less than the size of the collection. Parameter name: index in AnimationCurve.GetKey",
  "signature_zh": "ArgumentOutOfRangeException：索引超出范围。必须为非负数且小于集合大小。参数名：index 在 AnimationCurve.GetKey 中",
  "regex": "ArgumentOutOfRangeException: Index is out of range. Must be non-negative and less than the size of the collection. Parameter name: index in AnimationCurve\\.GetKey",
  "domain": "unity",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Attempting to access an AnimationCurve key at an index that does not exist, often due to modifying the curve's keys (adding/removing) without updating the index variable.",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试访问 AnimationCurve 中不存在的索引处的键，通常是由于修改了曲线的键（添加/删除）而没有更新索引变量。",
  "versions": [
    {
      "version": "Unity 2022.3.12f1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Unity 2023.1.2f1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Unity 2021.3.30f1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This hides the bug but doesn't fix the logic; the curve may still have incorrect keys.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "AnimationCurve may have multiple keys; using index 0 only accesses the first key, leading to wrong animation data.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Wrap modes affect evaluation, not key access by index.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Before accessing a key, check the curve's key count and ensure the index is valid. Use curve.keys.Length to get the count and clamp the index.",
      "success_rate": 0.9,
      "how": "Before accessing a key, check the curve's key count and ensure the index is valid. Use curve.keys.Length to get the count and clamp the index.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If dynamically adding keys, use curve.AddKey() which returns the index of the new key; store that index for later access instead of assuming a fixed index.",
      "success_rate": 0.85,
      "how": "If dynamically adding keys, use curve.AddKey() which returns the index of the new key; store that index for later access instead of assuming a fixed index.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Before accessing a key, check the curve's key count and ensure the index is valid. Use curve.keys.Length to get the count and clamp the index.",
    "If dynamically adding keys, use curve.AddKey() which returns the index of the new key; store that index for later access instead of assuming a fixed index."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.unity3d.com/ScriptReference/AnimationCurve.GetKey.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.83,
  "fix_success_rate": 0.88,
  "resolvable": "true",
  "first_seen": "2023-07-22",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}