Unity-Technologies/UnityCsReference · error · ArgumentException
The maximum number of sorted columns is {state.maximumNumber
Error message
The maximum number of sorted columns is {state.maximumNumberOfSortedColumns}. Trying to set {columnIndices.Length} columns. What it means
Thrown by SetSortingColumns when the number of sorted columns exceeds state.maximumNumberOfSortedColumns. The header only supports a bounded number of simultaneous sort keys for performance and display reasons.
Source
Thrown at Editor/Mono/GUI/TreeView/MultiColumnHeader.cs:81
public MultiColumnHeader(MultiColumnHeaderState state)
{
m_State = state;
m_HeaderButtonsControlID = GUIUtility.GetPermanentControlID();
}
public void SetSortingColumns(int[] columnIndices, bool[] sortAscending)
{
if (columnIndices == null)
throw new ArgumentNullException("columnIndices");
if (sortAscending == null)
throw new ArgumentNullException("sortAscending");
if (columnIndices.Length != sortAscending.Length)
throw new ArgumentException("Input arrays should have same length");
if (columnIndices.Length > state.maximumNumberOfSortedColumns)
throw new ArgumentException("The maximum number of sorted columns is " + state.maximumNumberOfSortedColumns + ". Trying to set " + columnIndices.Length + " columns.");
if (columnIndices.Length != columnIndices.DistinctCount())
throw new ArgumentException("Duplicate column indices are not allowed", "columnIndices");
bool changed = false;
if (!columnIndices.AsSpan().SequenceEqual(state.sortedColumns))
{
state.sortedColumns = columnIndices;
changed = true;
}
for (int i = 0; i < columnIndices.Length; ++i)
{
var column = GetColumn(columnIndices[i]);
if (column.sortedAscending != sortAscending[i])
{
column.sortedAscending = sortAscending[i];View on GitHub (pinned to 225b0fbdb5)
Solutions
- Limit the sort columns to the first N where N <= state.maximumNumberOfSortedColumns.
- Raise maximumNumberOfSortedColumns if the use case genuinely needs more sort keys.
- Validate against the cap before persisting user sort preferences.
Example fix
// before header.SetSortingColumns(cols, flags); // cols.Length > max // after int max = header.state.maximumNumberOfSortedColumns; header.SetSortingColumns(cols.Take(max).ToArray(), flags.Take(max).ToArray());
Defensive patterns
Strategy: validation
Validate before calling
int max = header.state.maximumNumberOfSortedColumns; var cappedCols = columnIndices.Take(max).ToArray(); var cappedFlags = sortAscending.Take(max).ToArray();
Prevention
- Read maximumNumberOfSortedColumns before building the sort arrays.
- Persist sort state only after validating against the current cap.
- Document the cap to users in the multi-sort UI.
When it happens
Trigger: Passing more sort columns than maximumNumberOfSortedColumns (typically 3); restoring a saved sort configuration that was created with a higher limit.
Common situations: Changing maximumNumberOfSortedColumns to a lower value but retaining old persisted sort state; a feature that adds multi-level sorting beyond the configured cap.
Related errors
- MultiColumnHeader state is not allowed to be null
- columnIndices
- sortAscending
- Input arrays should have same length
- Duplicate column indices are not allowed
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/894ca71be26d3adb.
Report an issue: GitHub.