Unity-Technologies/UnityCsReference · error · NotSupportedException

Only call this method if you are using a MultiColumnHeader w

Error message

Only call this method if you are using a MultiColumnHeader with the TreeView.

What it means

Thrown by RowGUIArgs.GetNumVisibleColumns when the TreeView is not using a MultiColumnHeader (HasMultiColumnInfo returns false). The method returns the count of visible columns from the column info struct, which only exists when the TreeView was constructed with a MultiColumnHeader.

Source

Thrown at Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControl.cs:871

            }
        }

        // Nested because they are used by protected methods
        protected internal struct RowGUIArgs
        {
            public TreeViewItem<TIdentifier> item;
            public string label;
            public Rect rowRect;
            public int row;
            public bool selected;
            public bool focused;
            public bool isRenaming;
            internal MultiColumnInfo columnInfo { get; set; }

            public int GetNumVisibleColumns()
            {
                if (!HasMultiColumnInfo())
                    throw new NotSupportedException("Only call this method if you are using a MultiColumnHeader with the TreeView.");

                return columnInfo.multiColumnHeaderState.visibleColumns.Length;
            }

            public int GetColumn(int visibleColumnIndex)
            {
                if (!HasMultiColumnInfo())
                    throw new NotSupportedException("Only call this method if you are using a MultiColumnHeader with the TreeView.");

                return columnInfo.multiColumnHeaderState.visibleColumns[visibleColumnIndex];
            }

            public Rect GetCellRect(int visibleColumnIndex)
            {
                if (!HasMultiColumnInfo())
                    throw new NotSupportedException("Only call this method if you are using a MultiColumnHeader with the TreeView.");

                return columnInfo.cellRects[visibleColumnIndex];

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Guard with args.HasMultiColumnInfo() before calling GetNumVisibleColumns().
  2. Branch RowGUI logic based on whether a MultiColumnHeader is present.
  3. Use the MultiColumnHeader TreeView constructor if column iteration is needed.

Example fix

// before
for (int i = 0; i < args.GetNumVisibleColumns(); i++) { ... }

// after
if (!args.HasMultiColumnInfo()) { base.RowGUI(args); return; }
for (int i = 0; i < args.GetNumVisibleColumns(); i++) { ... }
Defensive patterns

Strategy: type-guard

Validate before calling

if (args.HasMultiColumnInfo())
{
    for (int i = 0; i < args.GetNumVisibleColumns(); i++) { ... }
}

Type guard

// HasMultiColumnInfo() is the built-in guard on RowGUIArgs
bool safe = args.HasMultiColumnInfo();

Prevention

When it happens

Trigger: Calling args.GetNumVisibleColumns() inside RowGUI on a single-column TreeView; calling before columnInfo was set; using shared RowGUI code across both single- and multi-column TreeView subclasses.

Common situations: Overriding RowGUI and unconditionally iterating visible columns; code copied from a multi-column example into a single-column TreeView.

Related errors


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