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

  1. Ensure the array passed to visibleColumns always contains at least one valid column index before assignment.
  2. Guard your column-filtering logic: if the filtered result is empty, keep at least the primary column (usually index 0).
  3. 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

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


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