Unity-Technologies/UnityCsReference · error · ArgumentNullException

rows is null

Error message

rows is null

What it means

Thrown by AddExpandedRows when the rows list (IList<TreeViewItem>) argument is null. The method writes expanded rows into this list; a null list means there is no destination for the collected items.

Source

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

        }

        protected void CenterRectUsingSingleLineHeight(ref Rect rect)
        {
            float singleLineHeight = EditorGUIUtility.singleLineHeight;
            if (rect.height > singleLineHeight)
            {
                rect.y += (rect.height - singleLineHeight) * 0.5f;
                rect.height = singleLineHeight;
            }
        }

        protected void AddExpandedRows(TreeViewItem<TIdentifier> root, IList<TreeViewItem<TIdentifier>> rows)
        {
            if (root == null)
                throw new ArgumentNullException("root", "root is null");

            if (rows == null)
                throw new ArgumentNullException("rows", "rows is null");

            if (root.hasChildren)
                foreach (TreeViewItem<TIdentifier> child in root.children)
                    GetExpandedRowsRecursive(child, rows);
        }

        void GetExpandedRowsRecursive(TreeViewItem<TIdentifier> item, IList<TreeViewItem<TIdentifier>> expandedRows)
        {
            if (item == null)
                Debug.LogError("Found a TreeViewItem<TIdentifier> that is null. Invalid use of AddExpandedRows(): This method is only valid to call if you have built the full tree of TreeViewItems.");

            expandedRows.Add(item);

            if (item.hasChildren && IsExpanded(item.id))
                foreach (TreeViewItem<TIdentifier> child in item.children)
                    GetExpandedRowsRecursive(child, expandedRows);
        }

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Allocate the list before calling: var rows = new List<TreeViewItem<TIdentifier>>();
  2. Initialize the rows field at declaration or in the constructor.
  3. Add a null guard that allocates on demand.

Example fix

// before
AddExpandedRows(root, m_Rows); // m_Rows is null

// after
m_Rows = m_Rows ?? new List<TreeViewItem<TIdentifier>>();
AddExpandedRows(root, m_Rows);
Defensive patterns

Strategy: validation

Validate before calling

var rows = rows ?? new List<TreeViewItem<TIdentifier>>();
AddExpandedRows(root, rows);

Prevention

When it happens

Trigger: Calling AddExpandedRows(root, null); passing a field that was never allocated; a previous code path set the rows reference to null.

Common situations: Custom row-building override that forgets to allocate the list; refactoring that reordered initialization.

Related errors


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