{"record":{"id":"67f28d9531632454","repo":"Unity-Technologies/UnityCsReference","slug":"instance-instanceindex-has-not-materials","errorCode":null,"errorMessage":"instance {instanceIndex} has not materials","messagePattern":"instance (.+?) has not materials","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GI/LightBaker.bindings.cs","lineNumber":516,"sourceCode":"        {\n            if (index >= materialCount)\n                throw new ArgumentException($\"index must be between 0 and {materialCount - 1}, but was {index}\");\n            Material material = Internal_GetMaterial(index);\n            return material;\n        }\n        public void SetMaterial(uint index, Material material)\n        {\n            if (index >= materialCount)\n                throw new ArgumentException($\"index must be between 0 and {materialCount - 1}, but was {index}\");\n            Internal_SetMaterial(index, material);\n        }\n        public int GetMaterialIndex(uint instanceIndex, uint submeshIndex)\n        {\n            if (instanceIndex >= instanceCount)\n                throw new ArgumentException($\"instanceIndex must be between 0 and {instanceCount - 1}, but was {instanceIndex}\");\n            Instance theInstance = instance(instanceIndex);\n            if (theInstance.submeshMaterialIndices.Length == 0)\n                throw new ArgumentException($\"instance {instanceIndex} has not materials\");\n            if (submeshIndex >= theInstance.submeshMaterialIndices.Length)\n                throw new ArgumentException($\"submeshIndex must be between 0 and {theInstance.submeshMaterialIndices.Length - 1}, but was {submeshIndex}\");\n            return theInstance.submeshMaterialIndices[submeshIndex];\n        }\n        extern uint Internal_GetLightCount();\n        public uint GetLightCount()\n        {\n            return Internal_GetLightCount();\n        }\n        extern Light Internal_GetLight(uint index);\n        extern void Internal_SetLight(uint index, Light light);\n        public Light GetLight(uint index)\n        {\n            if (index >= GetLightCount())\n                throw new ArgumentException($\"index must be between 0 and {GetLightCount() - 1}, but was {index}\");\n            return Internal_GetLight(index);\n        }\n        public void SetLight(uint index, Light light)","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GI/LightBaker.bindings.cs#L498-L534","documentation":"GetMaterialIndex throws ArgumentException 'instance {n} has not materials' when the resolved Instance has submeshMaterialIndices.Length == 0. The instance passed the range guard but has no submesh->material mapping, so no submesh (including index 0) is valid. This indicates the instance contributed no materials to the bake (e.g. it was skipped or has no renderer materials).","triggerScenarios":"Calling GetMaterialIndex on an instance whose submeshMaterialIndices array is empty; iterating submeshes 0..k without first confirming the instance has any.","commonSituations":"Instances that were baked but stripped of materials; LOD/parent objects with no material assignment; assuming every instance has at least one material.","solutions":["Check theInstance.submeshMaterialIndices.Length > 0 before calling GetMaterialIndex.","Treat a material-less instance as 'no material' and skip/report it.","Investigate upstream if an instance you expect to have materials is empty."],"exampleFix":"// before\nint mIdx = lightBaker.GetMaterialIndex(instIdx, subIdx);\n\n// after\nInstance inst = lightBaker.instance(instIdx);\nif (inst.submeshMaterialIndices.Length == 0) continue;\nint mIdx = lightBaker.GetMaterialIndex(instIdx, subIdx);","handlingStrategy":"validation","validationCode":"Instance inst = lightBaker.instance(instanceIndex);\nif (inst.submeshMaterialIndices.Length > 0)\n    int mIdx = lightBaker.GetMaterialIndex(instanceIndex, submeshIndex);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check submeshMaterialIndices.Length > 0 before GetMaterialIndex.","Treat material-less instances as 'no material' and skip.","Investigate instances you expect to have materials but do not."],"tags":["gi","lightbaking","material","instance","validation","argument"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}