{"record":{"id":"c136f96776940efc","repo":"Unity-Technologies/UnityCsReference","slug":"columnindex-0-is-not-valid-when-the-current-colu","errorCode":null,"errorMessage":"columnIndex {0} is not valid when the current column count is {1}","messagePattern":"columnIndex (.+?) is not valid when the current column count is (.+?)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/MultiColumnHeader.cs","lineNumber":146,"sourceCode":"        public void SetSortDirection(int columnIndex, bool sortAscending)\n        {\n            var column = GetColumn(columnIndex);\n            if (column.sortedAscending != sortAscending)\n            {\n                column.sortedAscending = sortAscending;\n                OnSortingChanged();\n            }\n        }\n\n        public bool IsSortedAscending(int columnIndex)\n        {\n            return GetColumn(columnIndex).sortedAscending;\n        }\n\n        public MultiColumnHeaderState.Column GetColumn(int columnIndex)\n        {\n            if (columnIndex < 0 || columnIndex >= state.columns.Length)\n                throw new ArgumentOutOfRangeException(\"columnIndex\", string.Format(\"columnIndex {0} is not valid when the current column count is {1}\", columnIndex, state.columns.Length));\n            return state.columns[columnIndex];\n        }\n\n        public bool IsColumnVisible(int columnIndex)\n        {\n            foreach (int vc in state.visibleColumns)\n            {\n                if (vc == columnIndex)\n                    return true;\n            }\n            return false;\n        }\n\n        public int GetVisibleColumnIndex(int columnIndex)\n        {\n            for (int i = 0; i < state.visibleColumns.Length; i++)\n            {\n                if (state.visibleColumns[i] == columnIndex)","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/MultiColumnHeader.cs#L128-L164","documentation":"Thrown by MultiColumnHeader.GetColumn when columnIndex is negative or >= state.columns.Length. Every column accessor validates bounds because the columns array is the source of truth for width, sorting, and header content.","triggerScenarios":"Requesting a column by an index that doesn't exist; using a visible-column index where a full column index is expected.","commonSituations":"Columns were removed but a stale index was persisted; confusing visible column indices with absolute column indices.","solutions":["Bounds-check columnIndex against state.columns.Length before calling.","Clamp or ignore out-of-range indices when restoring saved state.","Use IsColumnVisible / GetVisibleColumnIndex to translate between the two index spaces correctly."],"exampleFix":"// before\nvar col = header.GetColumn(idx);\n\n// after\nif (idx >= 0 && idx < header.state.columns.Length)\n    var col = header.GetColumn(idx);\nelse return; // invalid index, skip","handlingStrategy":"validation","validationCode":"if (columnIndex < 0 || columnIndex >= header.state.columns.Length) return default;","typeGuard":"static bool IsValidColumnIndex(int i, MultiColumnHeader h) => i >= 0 && i < h.state.columns.Length;","tryCatchPattern":null,"preventionTips":["Recompute cached indices whenever columns are added or removed.","Distinguish absolute column indices from visible indices in your data model.","Bounds-check before any GetColumn call."],"tags":["unity-editor","treeview","multicolumn","bounds-check"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}