Unity-Technologies/UnityCsReference · error · ArgumentOutOfRangeException
columnIndex {0} is not valid when the current column count i
Error message
columnIndex {0} is not valid when the current column count is {1} What it means
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.
Source
Thrown at Editor/Mono/GUI/TreeView/MultiColumnHeader.cs:146
public void SetSortDirection(int columnIndex, bool sortAscending)
{
var column = GetColumn(columnIndex);
if (column.sortedAscending != sortAscending)
{
column.sortedAscending = sortAscending;
OnSortingChanged();
}
}
public bool IsSortedAscending(int columnIndex)
{
return GetColumn(columnIndex).sortedAscending;
}
public MultiColumnHeaderState.Column GetColumn(int columnIndex)
{
if (columnIndex < 0 || columnIndex >= state.columns.Length)
throw new ArgumentOutOfRangeException("columnIndex", string.Format("columnIndex {0} is not valid when the current column count is {1}", columnIndex, state.columns.Length));
return state.columns[columnIndex];
}
public bool IsColumnVisible(int columnIndex)
{
foreach (int vc in state.visibleColumns)
{
if (vc == columnIndex)
return true;
}
return false;
}
public int GetVisibleColumnIndex(int columnIndex)
{
for (int i = 0; i < state.visibleColumns.Length; i++)
{
if (state.visibleColumns[i] == columnIndex)View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before
var col = header.GetColumn(idx);
// after
if (idx >= 0 && idx < header.state.columns.Length)
var col = header.GetColumn(idx);
else return; // invalid index, skip Defensive patterns
Strategy: validation
Validate before calling
if (columnIndex < 0 || columnIndex >= header.state.columns.Length) return default;
Type guard
static bool IsValidColumnIndex(int i, MultiColumnHeader h) => i >= 0 && i < h.state.columns.Length;
Prevention
- 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.
When it happens
Trigger: Requesting a column by an index that doesn't exist; using a visible-column index where a full column index is expected.
Common situations: Columns were removed but a stale index was persisted; confusing visible column indices with absolute column indices.
Related errors
- The provided visibleColumnIndex is invalid. Ensure the index
- MultiColumnHeader state is not allowed to be null
- columnIndices
- sortAscending
- Input arrays should have same length
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/c136f96776940efc.
Report an issue: GitHub.