Unity-Technologies/UnityCsReference · error · ArgumentOutOfRangeException
Invalid index for columnIndexForTreeFoldouts: {0}. Number of
Error message
Invalid index for columnIndexForTreeFoldouts: {0}. Number of available columns: {1} What it means
Thrown by the setter of columnIndexForTreeFoldouts when the requested column index is outside the range of available columns ([0, multiColumnHeader.state.columns.Length)). The index must reference a real column so the foldout glyph can be placed within it.
Source
Thrown at Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControl.cs:199
set { m_GUI.extraSpaceBeforeIconAndLabel = value; }
}
protected float customFoldoutYOffset
{
get { return m_GUI.customFoldoutYOffset; }
set { m_GUI.customFoldoutYOffset = value; }
}
protected int columnIndexForTreeFoldouts
{
get { return m_GUI.columnIndexForTreeFoldouts; }
set
{
if (multiColumnHeader == null)
throw new InvalidOperationException("Setting columnIndexForTreeFoldouts can only be set when using TreeView with a MultiColumnHeader");
if (value < 0 || value >= multiColumnHeader.state.columns.Length)
throw new ArgumentOutOfRangeException("value", string.Format("Invalid index for columnIndexForTreeFoldouts: {0}. Number of available columns: {1}", value, multiColumnHeader.state.columns.Length));
m_GUI.columnIndexForTreeFoldouts = value;
}
}
protected bool useScrollView
{
get { return m_TreeView.useScrollView; }
set { m_TreeView.useScrollView = value; }
}
protected Rect GetCellRectForTreeFoldouts(Rect rowRect)
{
if (multiColumnHeader == null)
throw new InvalidOperationException("GetCellRect can only be called when 'multiColumnHeader' has been set");
int columnIndex = columnIndexForTreeFoldouts;
int visibleColumnIndex = multiColumnHeader.GetVisibleColumnIndex(columnIndex);View on GitHub (pinned to 225b0fbdb5)
Solutions
- Clamp the index to the valid range: columnIndexForTreeFoldouts = Mathf.Clamp(value, 0, header.state.columns.Length - 1).
- Verify the column count before assigning.
- Use index 0 (the first column) as a safe default for foldout placement.
Example fix
// before tree.columnIndexForTreeFoldouts = 3; // header only has 2 columns // after int max = header.state.columns.Length; tree.columnIndexForTreeFoldouts = Mathf.Clamp(3, 0, max - 1);
Defensive patterns
Strategy: validation
Validate before calling
int max = header.state.columns.Length; int idx = Mathf.Clamp(desiredIndex, 0, max - 1); tree.columnIndexForTreeFoldouts = idx;
Type guard
static bool IsValidColumnIndex(int idx, MultiColumnHeader h) => idx >= 0 && idx < h.state.columns.Length;
Prevention
- Clamp the foldout column index against the column count.
- Re-validate stored indices after changing the column count.
- Prefer index 0 as the default foldout column.
When it happens
Trigger: Setting columnIndexForTreeFoldouts to a value >= the number of columns defined in MultiColumnHeaderState; setting a negative value; setting an index after reducing the number of columns.
Common situations: Hardcoding an index (e.g. 2) when the header state was later changed to fewer columns; dynamic column removal that invalidates a previously-stored foldout column index.
Related errors
- Setting columnIndexForTreeFoldouts can only be set when usin
- visibleColumns should should not be set to an empty array. A
- GetCellRect can only be called when 'multiColumnHeader' has
- Only call this method if you are using a MultiColumnHeader w
- Input row index: {0} is invalid. Number of rows rects: {1}.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/03be37d2d376b78e.
Report an issue: GitHub.