Unity-Technologies/UnityCsReference · error · ArgumentException

visibleColumns should not be set to null

Error message

visibleColumns should not be set to null

What it means

Thrown by the MultiColumnHeaderState.visibleColumns setter when null is assigned. At least one visible column is required for the header to render any content, so null is explicitly rejected.

Source

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

            set
            {
                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. To show all columns, assign an array of all indices {0..columns.Length-1} rather than null.
  2. Null-coalesce loaded preferences: visibleColumns = loaded ?? allIndices.
  3. Guard the setter call with a null check and default to the full index set.

Example fix

// before
state.visibleColumns = loadedVisible; // may be null

// after
int[] all = Enumerable.Range(0, state.columns.Length).ToArray();
state.visibleColumns = loadedVisible ?? all;
Defensive patterns

Strategy: validation

Validate before calling

state.visibleColumns = value ?? Enumerable.Range(0, state.columns.Length).ToArray();

Type guard

static bool HasVisibleColumns(MultiColumnHeaderState s) => s.visibleColumns != null && s.visibleColumns.Length > 0;

Prevention

When it happens

Trigger: Assigning header.state.visibleColumns = null; binding to a visibility preference that deserialized to null.

Common situations: Resetting visibility to 'show all' but mistakenly assigning null; a corrupted preferences file yielding null for the visible-columns array.

Related errors


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