{"record":{"id":"7ee937c4813bc450","repo":"Unity-Technologies/UnityCsReference","slug":"attempting-to-retrieve-icon-layer-layer-while-t","errorCode":null,"errorMessage":"Attempting to retrieve icon layer {layer}, while the icon only contains {layerCount} layers!","messagePattern":"Attempting to retrieve icon layer (.+?), while the icon only contains (.+?) layers!","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/PlatformSupport/PlayerSettingsPlatformIcons.bindings.cs","lineNumber":136,"sourceCode":"\n        internal PlatformIcon(int width, int height, int minLayerCount, int maxLayerCount, string iconSubKind, string description, PlatformIconKind kind, bool draggable = true)\n        {\n            this.width = width;\n            this.height = height;\n            this.iconSubKind = iconSubKind;\n            this.description = description;\n            this.minLayerCount = minLayerCount;\n            this.maxLayerCount = maxLayerCount;\n            this.kind = kind;\n            this.draggable = draggable;\n\n            m_Textures = new List<Texture2D>();\n        }\n\n        public Texture2D GetTexture(int layer = 0)\n        {\n            if (layer < 0 || layer >= maxLayerCount)\n                throw new ArgumentOutOfRangeException($\"Attempting to retrieve icon layer {layer}, while the icon only contains {layerCount} layers!\");\n            return layer < layerCount ? m_Textures[layer] : null;\n        }\n\n        public Texture2D[] GetTextures()\n        {\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","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/PlatformSupport/PlayerSettingsPlatformIcons.bindings.cs#L118-L154","documentation":"Thrown by PlatformIcon.GetTexture(int layer) when the requested layer index is negative or greater-than-or-equal to maxLayerCount. The icon's layer capacity is fixed by its description (minLayerCount to maxLayerCount range), so requesting a layer beyond that capacity is an out-of-bounds access. Note: the message uses layerCount (currently populated textures) but the guard checks against maxLayerCount.","triggerScenarios":"Calling GetTexture with layer >= maxLayerCount or layer < 0. Happens when iterating layers using an array length from a different icon kind, or when hard-coding a layer index that exceeds the platform's supported layer count for that icon kind.","commonSituations":"Setting platform icons programmatically across multiple build targets that have different layer counts; assuming all icon kinds have the same number of layers; copying texture-access code from one platform to another without adjusting layer bounds.","solutions":["Check icon.maxLayerCount before accessing a specific layer: if (layer >= 0 && layer < icon.maxLayerCount).","Use GetTextures() to retrieve all textures as an array when you need to iterate without index assumptions.","Query GetValidLayerCount() to know how many layers are actually populated before indexing."],"exampleFix":"// before\nvar tex = icon.GetTexture(3); // icon only supports 2 layers\n\n// after\nvar tex = (3 < icon.maxLayerCount) ? icon.GetTexture(3) : null;","handlingStrategy":"validation","validationCode":"if (layer < 0 || layer >= icon.maxLayerCount)\n    return null;\nreturn icon.GetTexture(layer);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always check icon.maxLayerCount before indexing into icon layers.","Use GetTextures() for iteration-free bulk access.","Query GetValidLayerCount() to know how many textures are actually populated."],"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"}