Unity-Technologies/UnityCsReference · error · ArgumentNullException
columnIndices
Error message
columnIndices
What it means
Thrown by MultiColumnHeader.SetSortingColumns when the columnIndices array is null. The method pairs each column index with a sort-ascending flag, so a null column array makes the operation impossible.
Source
Thrown at Editor/Mono/GUI/TreeView/MultiColumnHeader.cs:72
get { return m_State; }
set
{
if (value == null)
throw new ArgumentNullException("state", "MultiColumnHeader state is not allowed to be null");
m_State = value;
}
}
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;View on GitHub (pinned to 225b0fbdb5)
Solutions
- Pass an empty int array (Array.Empty<int>()) instead of null to clear sorting.
- Initialize columnIndices before the call; default to the currently sorted columns.
- Null-check at the caller and substitute a sensible default.
Example fix
// before header.SetSortingColumns(sortCols, sortAsc); // sortCols may be null // after int[] cols = sortCols ?? Array.Empty<int>(); bool[] asc = sortAsc ?? Array.Empty<bool>(); header.SetSortingColumns(cols, asc);
Defensive patterns
Strategy: validation
Validate before calling
int[] cols = columnIndices ?? Array.Empty<int>();
Type guard
static bool IsValidSortArray(int[] a) => a != null;
Prevention
- Use Array.Empty<int>() to represent 'no sort columns' instead of null.
- Coalesce nullable sort sources before calling SetSortingColumns.
- Keep sort column sources initialized at declaration.
When it happens
Trigger: Calling SetSortingColumns(null, sortFlags); passing a lazily-initialized array that was never populated.
Common situations: Resetting sort to defaults but passing null instead of an empty array; a binding that yields null when no sort columns are configured.
Related errors
- MultiColumnHeader state is not allowed to be null
- sortAscending
- columns are no allowed to be null
- visibleColumns should not be set to null
- Input arrays should have same length
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/054fc54abfacc174.
Report an issue: GitHub.