Unity-Technologies/UnityCsReference · error · InvalidOperationException
Attempting to set an incorrect number of icons for {buildTar
Error message
Attempting to set an incorrect number of icons for {buildTarget.TargetName} {kind} kind, it requires {requiredIconCount} icons but trying to assign {icons.Length}. What it means
Thrown when setting platform icons for a specific build target and icon kind, and the number of PlatformIcon objects provided does not equal the required count returned by PlatformIcon.GetRequiredPlatformIconsByType. Each (buildTarget, kind) pair has a fixed required number of icons, and this method enforces that the array length matches exactly before forwarding to the native SetPlatformIconsInternal.
Source
Thrown at Editor/Mono/PlatformSupport/PlayerSettingsPlatformIcons.bindings.cs:345
public static void SetPlatformIcons(NamedBuildTarget buildTarget, PlatformIconKind kind, PlatformIcon[] icons)
{
if (!BuildTargetDiscovery.TryGetBuildTarget(BuildPipeline.GetBuildTargetByName(buildTarget.TargetName), out var iBuildTarget))
return;
var requiredIcons = iBuildTarget.IconPlatformProperties?.GetRequiredPlatformIcons();
if (requiredIcons == null)
return;
var requiredIconCount = PlatformIcon.GetRequiredPlatformIconsByType(kind, 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 {buildTarget.TargetName} {kind} kind, it requires {requiredIconCount} icons but trying to assign {icons.Length}.");
}
else
{
iconStructs = Array.ConvertAll(icons, i => i.GetPlatformIconStruct());
}
SetPlatformIconsInternal(buildTarget.TargetName, iconStructs, kind.kind);
}
[Obsolete("Use GetSupportedIconKinds(NamedBuildTarget) instead")]
public static PlatformIconKind[] GetSupportedIconKindsForPlatform(BuildTargetGroup platform) =>
GetSupportedIconKinds(NamedBuildTarget.FromBuildTargetGroup(platform));
public static PlatformIconKind[] GetSupportedIconKinds(NamedBuildTarget buildTarget)
{
if (BuildTargetDiscovery.TryGetBuildTarget(BuildPipeline.GetBuildTargetByName(buildTarget.TargetName), out var iBuildTarget))
{
var requiredIcons = iBuildTarget.IconPlatformProperties?.GetRequiredPlatformIcons();View on GitHub (pinned to 225b0fbdb5)
Solutions
- Query the required count first: var required = PlatformIcon.GetRequiredPlatformIconsByType(kind, availableIcons); and size your array to match before calling set.
- Fetch the correct icon set per build target/kind using GetIcons(NamedBuildTarget) or GetIconsForPublishing to get properly-sized arrays.
- Avoid reusing icon arrays across platforms — each (target, kind) pair may require a different number of icons.
Example fix
// before
SetPlatformIcons(buildTarget, kind, myIcons); // length mismatch
// after
var requiredCount = PlatformIcon.GetRequiredPlatformIconsByType(kind, availableIcons).Length;
if (myIcons.Length == requiredCount)
SetPlatformIcons(buildTarget, kind, myIcons); Defensive patterns
Strategy: validation
Validate before calling
var requiredCount = PlatformIcon.GetRequiredPlatformIconsByType(kind, availableIcons).Length;
if (icons != null && icons.Length == requiredCount)
SetPlatformIcons(buildTarget, kind, icons); Prevention
- Query the required icon count per (buildTarget, kind) before assembling your array.
- Use GetIcons(NamedBuildTarget) to fetch properly-sized icon arrays per platform.
- Never reuse icon arrays across platforms with different required counts.
When it happens
Trigger: Calling SetPlatformIcons (or the property setter that invokes it) with an icons array whose Length != requiredIconCount for that build target and kind. Occurs when the caller builds the icon array for one platform/kind and applies it to a different one with a different required count.
Common situations: Editor scripts that bulk-configure icons across platforms; copying icon arrays between build targets; Unity version upgrades that change the required icon count for a platform; custom build pipelines that don't query the required count per kind.
Related errors
- Attempting to assign an incorrect amount of layers to an Pla
- Attempting to retrieve icon layer {layer}, while the icon on
- Attempting to set icon layer {layer}, while icon only suppor
- The provided target platform group name ({buildTargetName})
- Trying to create a second main window from layout when one a
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/90c69ac289716656.
Report an issue: GitHub.