{"record":{"id":"50005cf5e4c3d0e2","repo":"Unity-Technologies/UnityCsReference","slug":"attempting-to-assign-an-incorrect-amount-of-layers","errorCode":null,"errorMessage":"Attempting to assign an incorrect amount of layers to an PlatformIcon, trying to assign {textures.Length} textures while the Icon requires atleast {minLayerCount} but no more than {maxLayerCount} layers","messagePattern":"Attempting to assign an incorrect amount of layers to an PlatformIcon, trying to assign (.+?) textures while the Icon requires atleast (.+?) but no more than (.+?) layers","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/PlatformSupport/PlayerSettingsPlatformIcons.bindings.cs","lineNumber":179,"sourceCode":"            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)\n            {\n                throw new InvalidOperationException($\"Attempting to assign an incorrect amount of layers to an PlatformIcon, trying to assign {textures.Length} textures while the Icon requires atleast {minLayerCount} but no more than {maxLayerCount} layers\");\n            }\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            m_Textures = textures.ToList();\n#pragma warning restore UA2001\n        }\n\n        internal int GetValidLayerCount()\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            var validLayerCount = m_Textures.Count(t => t != null);\n#pragma warning restore UA2001\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            var previewTexturesCount = GetPreviewTextures().Count(t => t != null);\n#pragma warning restore UA2001\n\n            return Math.Max(previewTexturesCount, validLayerCount);\n        }","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/PlatformSupport/PlayerSettingsPlatformIcons.bindings.cs#L161-L197","documentation":"Thrown by PlatformIcon.SetTextures(params Texture2D[] textures) when the number of textures provided falls outside the icon's valid layer range [minLayerCount, maxLayerCount]. Each platform icon kind has a fixed required layer count, so assigning the wrong number of textures is a contract violation. Note: if all textures are null or the array is empty, the method silently clears instead of throwing.","triggerScenarios":"Calling SetTextures with an array whose Length is less than minLayerCount or greater than maxLayerCount for that specific icon kind. Commonly occurs when fetching icons from one build target and applying them to another with a different layer requirement, or when deserializing icon data that doesn't match the target platform spec.","commonSituations":"Cross-platform icon automation scripts; batch-importing icon sets; mismatch between the icon kind selected and the number of textures in the source asset; upgrading a project to a Unity version where a platform's icon layer count changed.","solutions":["Check icon.minLayerCount and icon.maxLayerCount before calling SetTextures, and ensure your array length is within that range.","Pad or trim the texture array to the required count: Array.Resize(ref textures, icon.maxLayerCount).","Query the platform's icon kind specifications via GetIconsForPublishing or similar API to discover expected layer counts before assignment."],"exampleFix":"// before\nicon.SetTextures(textures); // textures.Length doesn't match\n\n// after\nif (textures.Length >= icon.minLayerCount && textures.Length <= icon.maxLayerCount)\n    icon.SetTextures(textures);","handlingStrategy":"validation","validationCode":"if (textures.Length >= icon.minLayerCount && textures.Length <= icon.maxLayerCount)\n    icon.SetTextures(textures);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check icon.minLayerCount and icon.maxLayerCount before calling SetTextures.","Pad or trim texture arrays to match the icon's required layer count.","Query per-platform icon specifications to discover expected layer counts before assignment."],"tags":["unity-editor","player-settings","platform-icons","invalid-operation","argument-validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}