Unity-Technologies/UnityCsReference · error · ArgumentException

The provided visibleColumnIndex is invalid. Ensure the index

Error message

The provided visibleColumnIndex is invalid. Ensure the index ({0}) is within the number of visible columns ({1})

What it means

Thrown by GetColumnRect when visibleColumnIndex is negative or >= m_ColumnRects.Length. The cached rectangle array is sized to the visible columns, so an out-of-range index has no geometry to return.

Source

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

                if (state.visibleColumns[i] == columnIndex)
                    return i;
            }
            string visibleIndices = string.Join(", ", state.visibleColumns);
            throw new ArgumentException(string.Format("Invalid columnIndex: {0}. The index is not part of the current visible columns: {1}", columnIndex, visibleIndices), "columnIndex");
        }

        public Rect GetCellRect(int visibleColumnIndex, Rect rowRect)
        {
            Rect result = GetColumnRect(visibleColumnIndex);
            result.y = rowRect.y;
            result.height = rowRect.height;
            return result;
        }

        public Rect GetColumnRect(int visibleColumnIndex)
        {
            if (visibleColumnIndex < 0 || visibleColumnIndex >= m_ColumnRects.Length)
                throw new ArgumentException(string.Format("The provided visibleColumnIndex is invalid. Ensure the index ({0}) is within the number of visible columns ({1})", visibleColumnIndex, m_ColumnRects.Length), "visibleColumnIndex");

            return m_ColumnRects[visibleColumnIndex];
        }

        public void ResizeToFit()
        {
            m_ResizeToFit = true;
            Repaint();
        }

        void UpdateColumnHeaderRects(Rect totalHeaderRect)
        {
            if (m_ColumnRects == null || m_ColumnRects.Length != state.visibleColumns.Length)
                m_ColumnRects = new Rect[state.visibleColumns.Length];

            Rect curRect = totalHeaderRect;
            for (int v = 0; v < state.visibleColumns.Length; v++)
            {

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Convert to a visible index via GetVisibleColumnIndex and ensure it is within [0, visibleColumns.Length).
  2. Defer rect queries until after the first layout pass / Repaint.
  3. Guard against m_ColumnRects being empty (early return).

Example fix

// before
var r = header.GetColumnRect(absoluteIdx);

// after
int vIdx = header.GetVisibleColumnIndex(absoluteIdx);
if (vIdx >= 0 && vIdx < header.state.visibleColumns.Length)
    var r = header.GetColumnRect(vIdx);
Defensive patterns

Strategy: validation

Validate before calling

if (visibleColumnIndex < 0 || visibleColumnIndex >= header.state.visibleColumns.Length) return Rect.zero;

Type guard

static bool IsValidVisibleIndex(int i, MultiColumnHeader h) => i >= 0 && i < h.state.visibleColumns.Length;

Prevention

When it happens

Trigger: Using an absolute column index where a visible-position (0..visibleCount-1) index is required; calling before the header rects have been laid out (empty m_ColumnRects).

Common situations: Confusing the two index spaces; querying rects during initial layout before UpdateColumnHeaderRects has populated the cache.

Related errors


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