{"record":{"id":"521e9717c51cd0f9","repo":"Unity-Technologies/UnityCsReference","slug":"submeshindex-must-be-between-0-and-submeshcount","errorCode":null,"errorMessage":"submeshIndex must be between 0 and {submeshCount - 1}, but was {submeshIndex}","messagePattern":"submeshIndex must be between 0 and (.+?), but was (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GI/LightBaker.bindings.cs","lineNumber":562,"sourceCode":"        {\n            if (instanceIndex >= instanceCount)\n                throw new ArgumentException($\"index must be between 0 and {instanceCount - 1}, but was {instanceIndex}\");\n            return Internal_instanceAlbedoEmissiveIndex(instanceIndex);\n        }\n        public int instanceToEmissiveIndex(uint instanceIndex)\n        {\n            if (instanceIndex >= instanceCount)\n                throw new ArgumentException($\"index must be between 0 and {instanceCount - 1}, but was {instanceIndex}\");\n            return Internal_instanceAlbedoEmissiveIndex(instanceIndex);\n        }\n        public int instanceToTransmissiveIndex(uint instanceIndex, uint submeshIndex)\n        {\n            if (instanceIndex >= instanceCount)\n                throw new ArgumentException($\"index must be between 0 and {instanceCount - 1}, but was {instanceIndex}\");\n            Instance inst = instance(instanceIndex);\n            int submeshCount = inst.submeshMaterialIndices.Length;\n            if (submeshIndex >= submeshCount)\n                throw new ArgumentException($\"submeshIndex must be between 0 and {submeshCount - 1}, but was {submeshIndex}\");\n            int materialIndex = inst.submeshMaterialIndices[submeshIndex];\n            if (materialIndex == -1)\n                throw new ArgumentException($\"material for submesh {submeshIndex} did not exist.\");\n\n            return Internal_instanceTransmissiveIndex(instanceIndex, submeshIndex);\n        }\n\n        public extern uint albedoTextureCount { get; }\n        public extern uint albedoTexturePropertiesCount { get; }\n        extern TextureData Internal_GetAlbedoTextureData(uint index);\n        extern void Internal_SetAlbedoTextureData(uint index, TextureData textureData);\n\n        public TextureData GetAlbedoTextureData(uint index)\n        {\n            if (index >= albedoTextureCount)\n                throw new ArgumentException($\"index must be between 0 and {albedoTextureCount - 1}, but was {index}\");\n            return Internal_GetAlbedoTextureData(index);\n        }","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GI/LightBaker.bindings.cs#L544-L580","documentation":"instanceToTransmissiveIndex's second guard throws ArgumentException when submeshIndex >= inst.submeshMaterialIndices.Length. After the instance is valid, the submesh index is bounded by that instance's own submesh count (resolved via instance(instanceIndex)).","triggerScenarios":"Calling instanceToTransmissiveIndex with a submeshIndex not bounded by the instance's submesh count; reusing a submesh count from a different instance.","commonSituations":"Assuming uniform submesh counts across instances; hardcoded submesh indices for multi-submesh meshes; iterating with <=.","solutions":["Fetch the Instance and bound submeshIndex to its submeshMaterialIndices.Length.","Do not assume a shared submesh count.","Use strict < for the loop bound."],"exampleFix":"// before\nint tIdx = lightBaker.instanceToTransmissiveIndex(instIdx, subIdx);\n\n// after\nInstance inst = lightBaker.instance(instIdx);\nif (subIdx >= inst.submeshMaterialIndices.Length) continue;\nint tIdx = lightBaker.instanceToTransmissiveIndex(instIdx, subIdx);","handlingStrategy":"validation","validationCode":"Instance inst = lightBaker.instance(instanceIndex);\nint submeshCount = inst.submeshMaterialIndices.Length;\nif (submeshIndex < submeshCount)\n    int tIdx = lightBaker.instanceToTransmissiveIndex(instanceIndex, submeshIndex);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bound submeshIndex to the specific instance's submeshMaterialIndices.Length.","Submesh counts vary per instance; never assume uniformity.","Use strict < comparisons."],"tags":["gi","lightbaking","submesh","transmissive","validation","index","argument"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}