Unity-Technologies/UnityCsReference · error · InvalidOperationException
Attempting to set an incorrect number of icons for {namedBui
Error message
Attempting to set an incorrect number of icons for {namedBuildTarget} {kind} kind, it requires {requiredIconCount} icons but trying to assign {icons.Length}. What it means
Thrown by SetIconsForPlatform when the number of PlatformIcon textures provided does not equal the count required by PlatformIcon.GetRequiredPlatformIconsByType for the given kind and build target. Each platform/kind demands an exact icon set.
Source
Thrown at Editor/Mono/Inspector/PlayerSettingsEditor/PlayerSettingsIconsEditor.cs:333
if (m_RequiredIcons == null)
m_RequiredIcons = new Dictionary<PlatformIconKind, PlatformIcon[]>();
if (!m_RequiredIcons.ContainsKey(kind))
{
foreach (var requiredIcon in requiredIcons)
{
if (!m_RequiredIcons.ContainsKey(requiredIcon.Key))
m_RequiredIcons.Add(requiredIcon.Key, requiredIcon.Value);
}
}
var requiredIconCount = PlatformIcon.GetRequiredPlatformIconsByType(kind, m_RequiredIcons).Length;
PlatformIconStruct[] iconStructs;
if (icons == null)
iconStructs = Array.Empty<PlatformIconStruct>();
else if (requiredIconCount != icons.Length)
{
throw new InvalidOperationException($"Attempting to set an incorrect number of icons for {namedBuildTarget} {kind} kind, it requires {requiredIconCount} icons but trying to assign {icons.Length}.");
}
else
{
#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.
iconStructs = icons.Select(
#pragma warning restore UA2001
i => i.GetPlatformIconStruct()
).ToArray<PlatformIconStruct>();
}
allIcons = PlayerSettings.SetIconsForPlatformForTargetIcons(namedBuildTarget.TargetName, iconStructs, kind.kind, allIcons);
}
void SetPlatformIcons(BuildTargetGroup targetGroup, PlatformIconKind kind, PlatformIcon[] icons, ref BuildTargetIcons[] allIcons)
{
SetIconsForPlatform(targetGroup, icons, kind, ref allIcons);
SerializeIcons();
}View on GitHub (pinned to 225b0fbdb5)
Solutions
- Query PlatformIcon.GetRequiredPlatformIconsByType(kind, requiredIcons).Length first and size your icons array to match.
- Pad or trim the icons array to the exact required count before assigning.
- Use the per-platform icon editor UI to confirm the required set for that build target.
Example fix
// before
PlayerSettings.SetIconsForPlatform(namedBuildTarget, icons, kind);
// after
int required = PlatformIcon.GetRequiredPlatformIconsByType(kind, requiredIcons).Length;
if (icons.Length != required)
Array.Resize(ref icons, required);
PlayerSettings.SetIconsForPlatform(namedBuildTarget, icons, kind); Defensive patterns
Strategy: validation
Validate before calling
int required = PlatformIcon.GetRequiredPlatformIconsByType(kind, requiredIcons).Length; bool ok = icons != null && icons.Length == required;
Prevention
- Query required count first and size the array to match.
- Use per-platform icon sets.
When it happens
Trigger: Assigning icons via SetIconsForPlatform with an array length that does not match the required count for the named build target and PlatformIconKind. Mixing icon sets between platforms that require different resolutions.
Common situations: Importing icon configuration from another platform without resizing the array. Build automation passing a fixed icon array to multiple platforms. New platform requiring more icon sizes than supplied.
Related errors
- The setting label can't be null or empty.
- Missing name for {0}
- Scripting backend value {scriptingBackend} is not supported.
- renderingLayerNames is null or empty
- One or more transforms are null
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/f034f14d0e67c3d5.
Report an issue: GitHub.