{"record":{"id":"f034f14d0e67c3d5","repo":"Unity-Technologies/UnityCsReference","slug":"attempting-to-set-an-incorrect-number-of-icons-for","errorCode":null,"errorMessage":"Attempting to set an incorrect number of icons for {namedBuildTarget} {kind} kind, it requires {requiredIconCount} icons but trying to assign {icons.Length}.","messagePattern":"Attempting to set an incorrect number of icons for (.+?) (.+?) kind, it requires (.+?) icons but trying to assign (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Inspector/PlayerSettingsEditor/PlayerSettingsIconsEditor.cs","lineNumber":333,"sourceCode":"            if (m_RequiredIcons == null)\n                m_RequiredIcons = new Dictionary<PlatformIconKind, PlatformIcon[]>();\n            if (!m_RequiredIcons.ContainsKey(kind))\n            {\n                foreach (var requiredIcon in requiredIcons)\n                {\n                    if (!m_RequiredIcons.ContainsKey(requiredIcon.Key))\n                        m_RequiredIcons.Add(requiredIcon.Key, requiredIcon.Value);\n                }\n            }\n\n            var requiredIconCount = PlatformIcon.GetRequiredPlatformIconsByType(kind, m_RequiredIcons).Length;\n\n            PlatformIconStruct[] iconStructs;\n            if (icons == null)\n                iconStructs = Array.Empty<PlatformIconStruct>();\n            else if (requiredIconCount != icons.Length)\n            {\n                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}.\");\n            }\n            else\n            {\n#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.\n                iconStructs = icons.Select(\n#pragma warning restore UA2001\n                    i => i.GetPlatformIconStruct()\n                    ).ToArray<PlatformIconStruct>();\n            }\n\n            allIcons = PlayerSettings.SetIconsForPlatformForTargetIcons(namedBuildTarget.TargetName, iconStructs, kind.kind, allIcons);\n        }\n\n        void SetPlatformIcons(BuildTargetGroup targetGroup, PlatformIconKind kind, PlatformIcon[] icons, ref BuildTargetIcons[] allIcons)\n        {\n            SetIconsForPlatform(targetGroup, icons, kind, ref allIcons);\n            SerializeIcons();\n        }","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Inspector/PlayerSettingsEditor/PlayerSettingsIconsEditor.cs#L315-L351","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nPlayerSettings.SetIconsForPlatform(namedBuildTarget, icons, kind);\n\n// after\nint required = PlatformIcon.GetRequiredPlatformIconsByType(kind, requiredIcons).Length;\nif (icons.Length != required)\n    Array.Resize(ref icons, required);\nPlayerSettings.SetIconsForPlatform(namedBuildTarget, icons, kind);","handlingStrategy":"validation","validationCode":"int required = PlatformIcon.GetRequiredPlatformIconsByType(kind, requiredIcons).Length;\nbool ok = icons != null && icons.Length == required;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Query required count first and size the array to match.","Use per-platform icon sets."],"tags":["unity","editor","player-settings","icons","validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}