Unity-Technologies/UnityCsReference · error · ArgumentNullException
MultiColumnHeader state is not allowed to be null
Error message
MultiColumnHeader state is not allowed to be null
What it means
Thrown by the MultiColumnHeader.state setter when an attempt is made to assign null. The header requires a valid MultiColumnHeaderState to render columns, sort state, and visibility; a null state would break every downstream accessor.
Source
Thrown at Editor/Mono/GUI/TreeView/MultiColumnHeader.cs:58
{
get { return state.sortedColumnIndex; }
set
{
if (value != state.sortedColumnIndex)
{
state.sortedColumnIndex = value;
OnSortingChanged();
}
}
}
public MultiColumnHeaderState state
{
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");
View on GitHub (pinned to 225b0fbdb5)
Solutions
- Always assign a non-null MultiColumnHeaderState, constructing a default one if needed.
- Guard deserialization: if the loaded state is null, build a fresh MultiColumnHeaderState from the column definitions.
- Avoid reassigning state at all; mutate the existing state in place instead.
Example fix
// before header.state = loadedState; // loadedState may be null // after header.state = loadedState ?? new MultiColumnHeaderState(CreateDefaultColumns());
Defensive patterns
Strategy: validation
Validate before calling
header.state = newState ?? new MultiColumnHeaderState(CreateDefaultColumns());
Type guard
static bool HasState(MultiColumnHeader h) => h.state != null;
Prevention
- Never assign null to state; construct a default instead.
- Validate deserialized state and rebuild on failure.
- Prefer mutating existing state over replacing it.
When it happens
Trigger: Assigning header.state = null directly; replacing the state with the result of a function that returns null (e.g. a failed deserialization).
Common situations: Loading a serialized MultiColumnHeaderState that failed to deserialize; clearing state on dispose without intending to reset; a migration that constructs state conditionally.
Related errors
- columnIndices
- 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/d6206d17de02ee67.
Report an issue: GitHub.