{
  "id": "unity/shader-invalid-subshader-index",
  "signature": "Shader error in 'Custom/WaterShader': Invalid subshader index 5. Subshader count is 3.",
  "signature_zh": "着色器错误：在'Custom/WaterShader'中：无效的子着色器索引5。子着色器数量为3。",
  "regex": "Shader error in '[^']+': Invalid subshader index \\d+\\. Subshader count is \\d+",
  "domain": "unity",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A script references a subshader index that exceeds the number of subshaders defined in the shader file.",
  "root_cause_type": "generic",
  "root_cause_zh": "脚本引用的子着色器索引超过了着色器文件中定义的子着色器数量。",
  "versions": [
    {
      "version": "2021.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2022.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2023.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Adding unused subshaders bloats the shader and may cause compilation issues; the correct fix is to adjust the index, not the shader.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "High indices still trigger the same error if they exceed the count; the index must be within range.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Shader.Find returns the shader object, but index 0 may not be the intended subshader for all hardware.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Correct the subshader index in the script. For example, change material.shader = shader; material.SetShaderPassIndex(1); to material.shader = shader; material.SetShaderPassIndex(0); where index 0 is the first subshader.",
      "success_rate": 0.95,
      "how": "Correct the subshader index in the script. For example, change material.shader = shader; material.SetShaderPassIndex(1); to material.shader = shader; material.SetShaderPassIndex(0); where index 0 is the first subshader.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Add a fallback subshader at the end of the shader file to handle unexpected indices: SubShader { Tags { \"RenderType\"=\"Opaque\" } Pass { ... } }.",
      "success_rate": 0.75,
      "how": "Add a fallback subshader at the end of the shader file to handle unexpected indices: SubShader { Tags { \"RenderType\"=\"Opaque\" } Pass { ... } }.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use ShaderVariantCollection to precompile only the needed subshaders, avoiding runtime index errors.",
      "success_rate": 0.8,
      "how": "Use ShaderVariantCollection to precompile only the needed subshaders, avoiding runtime index errors.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Correct the subshader index in the script. For example, change material.shader = shader; material.SetShaderPassIndex(1); to material.shader = shader; material.SetShaderPassIndex(0); where index 0 is the first subshader.",
    "Add a fallback subshader at the end of the shader file to handle unexpected indices: SubShader { Tags { \"RenderType\"=\"Opaque\" } Pass { ... } }.",
    "Use ShaderVariantCollection to precompile only the needed subshaders, avoiding runtime index errors."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.unity3d.com/Manual/SL-SubShader.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-01-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}