Unity-Technologies/UnityCsReference · error · InvalidOperationException
Attempting to assign an incorrect amount of layers to an Pla
Error message
Attempting to assign an incorrect amount of layers to an PlatformIcon, trying to assign {textures.Length} textures while the Icon requires atleast {minLayerCount} but no more than {maxLayerCount} layers What it means
Thrown by PlatformIcon.SetTextures(params Texture2D[] textures) when the number of textures provided falls outside the icon's valid layer range [minLayerCount, maxLayerCount]. Each platform icon kind has a fixed required layer count, so assigning the wrong number of textures is a contract violation. Note: if all textures are null or the array is empty, the method silently clears instead of throwing.
Source
Thrown at Editor/Mono/PlatformSupport/PlayerSettingsPlatformIcons.bindings.cs:179
if (layer > m_Textures.Count - 1)
{
for (int i = m_Textures.Count; i <= layer; i++)
m_Textures.Add(null);
}
m_Textures[layer] = texture;
}
public void SetTextures(params Texture2D[] textures)
{
if (textures == null || textures.Length == 0 || textures.TrueForAll(t => t == null))
{
m_Textures.Clear();
return;
}
else if (textures.Length > maxLayerCount || textures.Length < minLayerCount)
{
throw new InvalidOperationException($"Attempting to assign an incorrect amount of layers to an PlatformIcon, trying to assign {textures.Length} textures while the Icon requires atleast {minLayerCount} but no more than {maxLayerCount} layers");
}
#pragma warning disable UA2001 // The Banned API Analyzer produces compile errors for any new Linq code. This pre-existing usage has been suppressed, but should be rewritten if possible.
m_Textures = textures.ToList();
#pragma warning restore UA2001
}
internal int GetValidLayerCount()
{
#pragma warning disable UA2001 // The Banned API Analyzer produces compile errors for any new Linq code. This pre-existing usage has been suppressed, but should be rewritten if possible.
var validLayerCount = m_Textures.Count(t => t != null);
#pragma warning restore UA2001
#pragma warning disable UA2001 // The Banned API Analyzer produces compile errors for any new Linq code. This pre-existing usage has been suppressed, but should be rewritten if possible.
var previewTexturesCount = GetPreviewTextures().Count(t => t != null);
#pragma warning restore UA2001
return Math.Max(previewTexturesCount, validLayerCount);
}View on GitHub (pinned to 225b0fbdb5)
Solutions
- Check icon.minLayerCount and icon.maxLayerCount before calling SetTextures, and ensure your array length is within that range.
- Pad or trim the texture array to the required count: Array.Resize(ref textures, icon.maxLayerCount).
- Query the platform's icon kind specifications via GetIconsForPublishing or similar API to discover expected layer counts before assignment.
Example fix
// before
icon.SetTextures(textures); // textures.Length doesn't match
// after
if (textures.Length >= icon.minLayerCount && textures.Length <= icon.maxLayerCount)
icon.SetTextures(textures); Defensive patterns
Strategy: validation
Validate before calling
if (textures.Length >= icon.minLayerCount && textures.Length <= icon.maxLayerCount)
icon.SetTextures(textures); Prevention
- Check icon.minLayerCount and icon.maxLayerCount before calling SetTextures.
- Pad or trim texture arrays to match the icon's required layer count.
- Query per-platform icon specifications to discover expected layer counts before assignment.
When it happens
Trigger: Calling SetTextures with an array whose Length is less than minLayerCount or greater than maxLayerCount for that specific icon kind. Commonly occurs when fetching icons from one build target and applying them to another with a different layer requirement, or when deserializing icon data that doesn't match the target platform spec.
Common situations: Cross-platform icon automation scripts; batch-importing icon sets; mismatch between the icon kind selected and the number of textures in the source asset; upgrading a project to a Unity version where a platform's icon layer count changed.
Related errors
- Attempting to retrieve icon layer {layer}, while the icon on
- Attempting to set icon layer {layer}, while icon only suppor
- Attempting to set an incorrect number of icons for {buildTar
- The provided target platform group name ({buildTargetName})
- Value cannot be null. (Parameter 'defines')
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/50005cf5e4c3d0e2.
Report an issue: GitHub.