Unity-Technologies/UnityCsReference · error · ArgumentException
instance has not materials
Error message
instance {instanceIndex} has not materials What it means
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).
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.
Example fix
// before int mIdx = lightBaker.GetMaterialIndex(instIdx, subIdx); // after Instance inst = lightBaker.instance(instIdx); if (inst.submeshMaterialIndices.Length == 0) continue; int mIdx = lightBaker.GetMaterialIndex(instIdx, subIdx);
Defensive patterns
Strategy: validation
Validate before calling
Instance inst = lightBaker.instance(instanceIndex);
if (inst.submeshMaterialIndices.Length > 0)
int mIdx = lightBaker.GetMaterialIndex(instanceIndex, submeshIndex); Prevention
- 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.
When it happens
Trigger: Calling GetMaterialIndex on an instance whose submeshMaterialIndices array is empty; iterating submeshes 0..k without first confirming the instance has any.
Common situations: Instances that were baked but stripped of materials; LOD/parent objects with no material assignment; assuming every instance has at least one material.
Related errors
- instanceIndex must be between 0 and
- index must be between 0 and
- index must be between 0 and
- material for submesh
- submeshIndex must be between 0 and
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/67f28d9531632454.
Report an issue: GitHub.
Appendix: source
Thrown at Editor/Mono/GI/LightBaker.bindings.cs:516
{
if (index >= materialCount)
throw new ArgumentException($"index must be between 0 and {materialCount - 1}, but was {index}");
Material material = Internal_GetMaterial(index);
return material;
}
public void SetMaterial(uint index, Material material)
{
if (index >= materialCount)
throw new ArgumentException($"index must be between 0 and {materialCount - 1}, but was {index}");
Internal_SetMaterial(index, material);
}
public int GetMaterialIndex(uint instanceIndex, uint submeshIndex)
{
if (instanceIndex >= instanceCount)
throw new ArgumentException($"instanceIndex must be between 0 and {instanceCount - 1}, but was {instanceIndex}");
Instance theInstance = instance(instanceIndex);
if (theInstance.submeshMaterialIndices.Length == 0)
throw new ArgumentException($"instance {instanceIndex} has not materials");
if (submeshIndex >= theInstance.submeshMaterialIndices.Length)
throw new ArgumentException($"submeshIndex must be between 0 and {theInstance.submeshMaterialIndices.Length - 1}, but was {submeshIndex}");
return theInstance.submeshMaterialIndices[submeshIndex];
}
extern uint Internal_GetLightCount();
public uint GetLightCount()
{
return Internal_GetLightCount();
}
extern Light Internal_GetLight(uint index);
extern void Internal_SetLight(uint index, Light light);
public Light GetLight(uint index)
{
if (index >= GetLightCount())
throw new ArgumentException($"index must be between 0 and {GetLightCount() - 1}, but was {index}");
return Internal_GetLight(index);
}
public void SetLight(uint index, Light light)View on GitHub (pinned to 225b0fbdb5)