Unity-Technologies/UnityCsReference · error · ArgumentException
visibleColumns should should not be set to an empty array. A
Error message
visibleColumns should should not be set to an empty array. At least one visible column is required.
What it means
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.
Source
Thrown at Editor/Mono/GUI/TreeView/MultiColumnHeaderState.cs:184
m_SortedColumns = value == null ? new List<int>() : new List<int>(value);
RemoveInvalidSortingColumnsIndices();
}
}
public Column[] columns
{
get { return m_Columns; }
}
public int[] visibleColumns
{
get { return m_VisibleColumns; }
set
{
if (value == null)
throw new ArgumentException("visibleColumns should not be set to null");
if (value.Length == 0)
throw new ArgumentException("visibleColumns should should not be set to an empty array. At least one visible column is required.");
m_VisibleColumns = value;
}
}
public float widthOfAllVisibleColumns
{
#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.
get { return visibleColumns.Sum(t => columns[t].width); }
#pragma warning restore UA2001
}
}
}
View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before
state.visibleColumns = visibleIndices.ToArray(); // could be empty
// after
var indices = visibleIndices.ToArray();
if (indices.Length == 0) indices = new[] { 0 };
state.visibleColumns = indices; Defensive patterns
Strategy: validation
Validate before calling
int[] next = ComputeVisibleIndices();
if (next == null || next.Length == 0)
next = new[] { 0 }; // always keep column 0
header.state.visibleColumns = next; Type guard
static bool HasAtLeastOneColumn(int[] cols) => cols != null && cols.Length > 0;
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Setting columnIndexForTreeFoldouts can only be set when usin
- Invalid index for columnIndexForTreeFoldouts: {0}. Number of
- GetCellRect can only be called when 'multiColumnHeader' has
- Only call this method if you are using a MultiColumnHeader w
- TreeView: 'rootItem.children == null'. Did you forget to add
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/6f593e16b9e9ca68.
Report an issue: GitHub.