{"record":{"id":"d073409b2da3398e","repo":"Unity-Technologies/UnityCsReference","slug":"attempting-to-set-icon-layer-layer-while-icon-o","errorCode":null,"errorMessage":"Attempting to set icon layer {layer}, while icon only supports {maxLayerCount} layers!","messagePattern":"Attempting to set icon layer (.+?), while icon only supports (.+?) layers!","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/PlatformSupport/PlayerSettingsPlatformIcons.bindings.cs","lineNumber":159,"sourceCode":"        {\n            return m_Textures.ToArray();\n        }\n\n        internal void SetPreviewTextures(Texture2D[] textures)\n        {\n            m_PreviewTextures = textures;\n        }\n\n        internal Texture2D[] GetPreviewTextures()\n        {\n            return m_PreviewTextures;\n        }\n\n        public void SetTexture(Texture2D texture, int layer = 0)\n        {\n            if (layer < 0 || layer >= maxLayerCount)\n            {\n                throw new ArgumentOutOfRangeException($\"Attempting to set icon layer {layer}, while icon only supports {maxLayerCount} layers!\");\n            }\n            if (layer > m_Textures.Count - 1)\n            {\n                for (int i = m_Textures.Count; i <= layer; i++)\n                    m_Textures.Add(null);\n            }\n\n            m_Textures[layer] = texture;\n        }\n\n        public void SetTextures(params Texture2D[] textures)\n        {\n            if (textures == null || textures.Length == 0 || textures.TrueForAll(t => t == null))\n            {\n                m_Textures.Clear();\n                return;\n            }\n            else if (textures.Length > maxLayerCount || textures.Length < minLayerCount)","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/PlatformSupport/PlayerSettingsPlatformIcons.bindings.cs#L141-L177","documentation":"Thrown by PlatformIcon.SetTexture(Texture2D texture, int layer) when the layer index is negative or exceeds maxLayerCount. Unlike GetTexture, SetTexture will auto-expand the internal m_Textures list up to maxLayerCount by padding with nulls, but it still rejects indices outside the valid range defined by the icon's kind description.","triggerScenarios":"Calling SetTexture with layer >= maxLayerCount or layer < 0. Happens when programmatically assigning textures to icon layers using indices derived from a different icon kind's layer layout, or when incrementing layer counters past the platform maximum.","commonSituations":"Bulk-setting icons across platforms with varying layer counts; editor scripts that assign textures in a loop without checking per-icon capacity; importing icon configuration from a format that doesn't match the target platform's layer schema.","solutions":["Validate against icon.maxLayerCount before calling SetTexture.","Use SetTextures(params Texture2D[]) to assign all layers at once after validating the array length falls within [minLayerCount, maxLayerCount].","When iterating, clamp or skip layers beyond capacity: for (int i = 0; i < Mathf.Min(textures.Length, icon.maxLayerCount); i++)."],"exampleFix":"// before\nicon.SetTexture(myTexture, 5); // icon.maxLayerCount is 3\n\n// after\nif (5 < icon.maxLayerCount)\n    icon.SetTexture(myTexture, 5);","handlingStrategy":"validation","validationCode":"if (layer >= 0 && layer < icon.maxLayerCount)\n    icon.SetTexture(texture, layer);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate layer index against icon.maxLayerCount before calling SetTexture.","Use SetTextures() for batch assignment after checking the count fits within [minLayerCount, maxLayerCount].","Do not assume all icon kinds share the same layer count across platforms."],"tags":["unity-editor","player-settings","platform-icons","argument-out-of-range","argument-validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}