{"record":{"id":"7eadc4a999c682e0","repo":"Unity-Technologies/UnityCsReference","slug":"index-must-be-between-0-and-emissivetexturecount","errorCode":null,"errorMessage":"index must be between 0 and {emissiveTextureCount - 1}, but was {index}","messagePattern":"index must be between 0 and (.+?), but was (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GI/LightBaker.bindings.cs","lineNumber":438,"sourceCode":"\n        public extern ulong GetByteSize();\n\n        public Texture2D GetAlbedoTexture(uint index)\n        {\n            if (index >= albedoTextureCount)\n                throw new ArgumentException($\"index must be between 0 and {albedoTextureCount - 1}, but was {index}\");\n            TextureData textureData = GetAlbedoTextureData(index);\n            Texture2D tex = new((int)textureData.resolution.width, (int)textureData.resolution.height, TextureFormat.RGBAFloat, false);\n            tex.SetPixelData(textureData.data, 0);\n            tex.filterMode = FilterMode.Point;\n            tex.Apply();\n            return tex;\n        }\n\n        public Texture2D GetEmissiveTexture(uint index)\n        {\n            if (index >= emissiveTextureCount)\n                throw new ArgumentException($\"index must be between 0 and {emissiveTextureCount - 1}, but was {index}\");\n            TextureData textureData = GetEmissiveTextureData(index);\n            Texture2D tex = new((int)textureData.resolution.width, (int)textureData.resolution.height, TextureFormat.RGBAFloat, false);\n            tex.SetPixelData(textureData.data, 0);\n            tex.filterMode = FilterMode.Point;\n            tex.Apply();\n            return tex;\n        }\n\n        static extern IntPtr Internal_Create();\n        [NativeMethod(IsThreadSafe = true)]\n        static extern void Internal_Destroy(IntPtr ptr);\n\n        extern LightingSettings Internal_GetLightingSettings();\n        public LightingSettings GetLightingSettings()\n        {\n            return Internal_GetLightingSettings();\n        }\n        extern void Internal_SetLightingSettings(LightingSettings lightingSettings);","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GI/LightBaker.bindings.cs#L420-L456","documentation":"LightBaker.GetEmissiveTexture(uint index) throws ArgumentException when index >= emissiveTextureCount. The emissive set is separate from the albedo set and may have a different count or be empty depending on whether the scene contains emissive materials. The guard mirrors GetAlbedoTexture and protects the native texture lookup.","triggerScenarios":"Assuming emissiveTextureCount equals albedoTextureCount and reusing the same loop bound; calling GetEmissiveTexture before a bake that produced emissive output.","commonSituations":"Scenes with no emissive materials yield emissiveTextureCount == 0; reusing an albedo-index to fetch emissive textures; stale count after re-bake.","solutions":["Read emissiveTextureCount independently and iterate [0, count).","Treat emissiveTextureCount == 0 as 'no emissive output' rather than an error.","Do not assume emissive and albedo counts match; index them separately."],"exampleFix":"// before\nvar emissive = lightBaker.GetEmissiveTexture(albedoIndex);\n\n// after\nfor (uint i = 0; i < lightBaker.emissiveTextureCount; i++)\n    yield return lightBaker.GetEmissiveTexture(i);","handlingStrategy":"validation","validationCode":"uint count = lightBaker.emissiveTextureCount;\nif (index < count)\n    var tex = lightBaker.GetEmissiveTexture(index);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not reuse the albedo count for emissive indexing; they differ.","Handle emissiveTextureCount == 0 (scenes without emissive materials) gracefully.","Re-query counts after each bake."],"tags":["gi","lightbaking","validation","index","argument"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}