{"record":{"id":"6f593e16b9e9ca68","repo":"Unity-Technologies/UnityCsReference","slug":"visiblecolumns-should-should-not-be-set-to-an-empt","errorCode":null,"errorMessage":"visibleColumns should should not be set to an empty array. At least one visible column is required.","messagePattern":"visibleColumns should should not be set to an empty array\\. At least one visible column is required\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/MultiColumnHeaderState.cs","lineNumber":184,"sourceCode":"                m_SortedColumns = value == null ? new List<int>() : new List<int>(value);\n                RemoveInvalidSortingColumnsIndices();\n            }\n        }\n\n        public Column[] columns\n        {\n            get { return m_Columns; }\n        }\n\n        public int[] visibleColumns\n        {\n            get { return m_VisibleColumns; }\n            set\n            {\n                if (value == null)\n                    throw new ArgumentException(\"visibleColumns should not be set to null\");\n                if (value.Length == 0)\n                    throw new ArgumentException(\"visibleColumns should should not be set to an empty array. At least one visible column is required.\");\n                m_VisibleColumns = value;\n            }\n        }\n\n        public float widthOfAllVisibleColumns\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            get { return visibleColumns.Sum(t => columns[t].width); }\n#pragma warning restore UA2001\n        }\n    }\n}\n","sourceCodeStart":166,"sourceCodeEnd":197,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/MultiColumnHeaderState.cs#L166-L197","documentation":"Thrown by the setter of MultiColumnHeaderState.visibleColumns when the assigned array has zero elements. The TreeView/MultiColumnHeader requires at least one visible column to render its header and rows, so an empty array is treated as an invalid configuration rather than a legitimate 'show nothing' state. The message contains a typo ('should should') that is harmless but recognizable.","triggerScenarios":"Assigning an empty int[] to multiColumnHeader.state.visibleColumns (e.g. state.visibleColumns = new int[0]{};), or programmatically filtering all columns out of the visible set and writing the result back.","commonSituations":"Serializing/deserializing a MultiColumnHeaderState whose visibleColumns array was cleared by a user collapsing all columns; dynamic column-hiding logic that filters visibleColumns down to nothing; copy-paste of a column setup that omitted the initial column index.","solutions":["Ensure the array passed to visibleColumns always contains at least one valid column index before assignment.","Guard your column-filtering logic: if the filtered result is empty, keep at least the primary column (usually index 0).","Initialize the state with visibleColumns = new[] { 0 } as a fallback default."],"exampleFix":"// before\nstate.visibleColumns = visibleIndices.ToArray(); // could be empty\n\n// after\nvar indices = visibleIndices.ToArray();\nif (indices.Length == 0) indices = new[] { 0 };\nstate.visibleColumns = indices;","handlingStrategy":"validation","validationCode":"int[] next = ComputeVisibleIndices();\nif (next == null || next.Length == 0)\n    next = new[] { 0 }; // always keep column 0\nheader.state.visibleColumns = next;","typeGuard":"static bool HasAtLeastOneColumn(int[] cols) => cols != null && cols.Length > 0;","tryCatchPattern":null,"preventionTips":["Never filter visibleColumns to empty; always retain a primary column.","Validate the array length before assigning to visibleColumns.","Unit-test column-hiding logic with the 'all hidden' edge case."],"tags":["unity","treeview","multicolumnheader","validation","configuration"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}