Unity-Technologies/UnityCsReference · error · ArgumentException
index must be between 0 and {albedoTexturePropertiesCount -
Error message
index must be between 0 and {albedoTexturePropertiesCount - 1}, but was {index} What it means
Thrown by BakeInput.GetAlbedoTextureProperties (the LightBaker bake-input object) when the supplied uint index is >= albedoTexturePropertiesCount. The properties collection is distinct from the albedo TextureData slots (albedoTextureCount): an index that is valid for data may be out of range for properties, so the count used to bound the loop must match the API being called.
Source
Thrown at Editor/Mono/GI/LightBaker.bindings.cs:591
extern void Internal_SetAlbedoTextureData(uint index, TextureData textureData);
public TextureData GetAlbedoTextureData(uint index)
{
if (index >= albedoTextureCount)
throw new ArgumentException($"index must be between 0 and {albedoTextureCount - 1}, but was {index}");
return Internal_GetAlbedoTextureData(index);
}
public void SetAlbedoTextureData(uint index, TextureData textureData)
{
if (index >= albedoTextureCount)
throw new ArgumentException($"index must be between 0 and {albedoTextureCount - 1}, but was {index}");
Internal_SetAlbedoTextureData(index, textureData);
}
extern TextureProperties Internal_GetAlbedoTextureProperties(uint index);
public TextureProperties GetAlbedoTextureProperties(uint index)
{
if (index >= albedoTexturePropertiesCount)
throw new ArgumentException($"index must be between 0 and {albedoTexturePropertiesCount - 1}, but was {index}");
return Internal_GetAlbedoTextureProperties(index);
}
extern void Internal_SetAlbedoTextureProperties(uint index, TextureProperties textureProperties);
public void SetAlbedoTextureProperties(uint index, TextureProperties textureProperties)
{
if (index >= albedoTexturePropertiesCount)
throw new ArgumentException($"index must be between 0 and {albedoTexturePropertiesCount - 1}, but was {index}");
Internal_SetAlbedoTextureProperties(index, textureProperties);
}
public extern uint emissiveTextureCount { get; }
public extern uint emissiveTexturePropertiesCount { get; }
public extern uint transmissiveTextureCount { get; }
public extern uint transmissiveTexturePropertiesCount { get; }
extern TextureData Internal_GetEmissiveTextureData(uint index);
extern void Internal_SetEmissiveTextureData(uint index, TextureData textureData);
public TextureData GetEmissiveTextureData(uint index)
{View on GitHub (pinned to 225b0fbdb5)
Solutions
- Bound the loop with the matching count: for (uint i = 0; i < bakeInput.albedoTexturePropertiesCount; i++) ...
- If data and properties must be 1:1, align/grow them during InputExtraction before calling Get.
- Guard the call site: if (index < bakeInput.albedoTexturePropertiesCount) { ... }
Example fix
// before
for (uint i = 0; i < bakeInput.albedoTextureCount; i++)
props.Add(bakeInput.GetAlbedoTextureProperties(i));
// after
for (uint i = 0; i < bakeInput.albedoTexturePropertiesCount; i++)
props.Add(bakeInput.GetAlbedoTextureProperties(i)); Defensive patterns
Strategy: validation
Validate before calling
if (index < bakeInput.albedoTexturePropertiesCount)
{
var p = bakeInput.GetAlbedoTextureProperties(index);
} Prevention
- Read the bound from the matching *Count property of the same prefix (properties vs data).
- Keep albedo data and properties arrays aligned during InputExtraction.
- Treat ArgumentException here as a caller bug, not a runtime hazard.
When it happens
Trigger: Calling bakeInput.GetAlbedoTextureProperties(i) inside a loop bounded by albedoTextureCount, instanceCount, or a scene mesh count while albedoTexturePropertiesCount is smaller; reading properties after InputExtraction populated TextureData but not TextureProperties.
Common situations: Custom bake readback pipelines that iterate albedo data and properties in lockstep assuming the two arrays are 1:1; off-by-one from using <= instead of <; reading properties on a BakeInput whose albedo properties were never populated.
Related errors
- index must be between 0 and {emissiveTexturePropertiesCount
- index must be between 0 and {transmissiveTexturePropertiesCo
- index must be between 0 and {transmissiveTextureCount - 1},
- index must be between 0 and {GetCookieCount() - 1}, but was
- index must be between 0 and {lightmapCount - 1}, but was {in
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/730c3c2f092070c1.
Report an issue: GitHub.