Unity-Technologies/UnityCsReference · error · ArgumentException

columns array should at least have one column: it is empty

Error message

columns array should at least have one column: it is empty

What it means

Thrown by the MultiColumnHeaderState constructor when the columns array is non-null but empty. A multi-column header requires at least one column to function, so a zero-length array is invalid.

Source

Thrown at Editor/Mono/GUI/TreeView/MultiColumnHeaderState.cs:77

#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.
            destination.m_VisibleColumns = source.m_VisibleColumns.ToArray();
#pragma warning restore UA2001
            destination.m_SortedColumns = new List<int>(source.m_SortedColumns);

            for (int i = 0; i < destination.m_Columns.Length; ++i)
            {
                destination.m_Columns[i].width = source.m_Columns[i].width;
                destination.m_Columns[i].sortedAscending = source.m_Columns[i].sortedAscending;
            }
        }

        public MultiColumnHeaderState(Column[] columns)
        {
            if (columns == null)
                throw new ArgumentException("columns are no allowed to be null", "columns");
            if (columns.Length == 0)
                throw new ArgumentException("columns array should at least have one column: it is empty", "columns");

            m_Columns = columns;
            m_SortedColumns = new List<int>();

            // Default to all visible
            m_VisibleColumns = new int[m_Columns.Length];
            for (int i = 0; i < m_Columns.Length; ++i)
                m_VisibleColumns[i] = i;
        }

        public int sortedColumnIndex
        {
            get
            {
                return m_SortedColumns.Count > 0 ? m_SortedColumns[0] : -1;
            }
            set
            {

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Ensure the column source yields at least one column; provide a default/fallback column.
  2. Skip constructing the header state when no columns exist and render an empty placeholder UI instead.
  3. Validate columns.Length > 0 before construction and log why no columns were produced.

Example fix

// before
var st = new MultiColumnHeaderState(cols); // cols.Length == 0

// after
if (cols.Length == 0) cols = new[] { new MultiColumnHeaderState.Column { headerContent = new GUIContent("-") } };
var st = new MultiColumnHeaderState(cols);
Defensive patterns

Strategy: validation

Validate before calling

if (columns.Length == 0) columns = new[] { new MultiColumnHeaderState.Column { headerContent = new GUIContent("(empty)") } };

Type guard

static bool HasAtLeastOne(Column[] c) => c != null && c.Length > 0;

Prevention

When it happens

Trigger: Passing 'new Column[0]' or Array.Empty<Column>(); a dynamic column source that legitimately produced zero columns.

Common situations: Feature-gated column sets where all columns are disabled; a filter that removed every column; an early-returning builder returning an empty array.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/e2a1c65e55b2840a. Report an issue: GitHub.