{"record":{"id":"d23b90f7508f3eed","repo":"Unity-Technologies/UnityCsReference","slug":"getcellrect-can-only-be-called-when-multicolumnhe","errorCode":null,"errorMessage":"GetCellRect can only be called when 'multiColumnHeader' has been set","messagePattern":"GetCellRect can only be called when 'multiColumnHeader' has been set","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControl.cs","lineNumber":214,"sourceCode":"                    throw new InvalidOperationException(\"Setting columnIndexForTreeFoldouts can only be set when using TreeView with a MultiColumnHeader\");\n\n                if (value < 0 || value >= multiColumnHeader.state.columns.Length)\n                    throw new ArgumentOutOfRangeException(\"value\", string.Format(\"Invalid index for columnIndexForTreeFoldouts: {0}. Number of available columns: {1}\", value, multiColumnHeader.state.columns.Length));\n\n                m_GUI.columnIndexForTreeFoldouts = value;\n            }\n        }\n\n        protected bool useScrollView\n        {\n            get { return m_TreeView.useScrollView; }\n            set { m_TreeView.useScrollView = value; }\n        }\n\n        protected Rect GetCellRectForTreeFoldouts(Rect rowRect)\n        {\n            if (multiColumnHeader == null)\n                throw new InvalidOperationException(\"GetCellRect can only be called when 'multiColumnHeader' has been set\");\n\n            int columnIndex = columnIndexForTreeFoldouts;\n            int visibleColumnIndex = multiColumnHeader.GetVisibleColumnIndex(columnIndex);\n            return multiColumnHeader.GetCellRect(visibleColumnIndex, rowRect);\n        }\n\n        protected float depthIndentWidth\n        {\n            get { return m_GUI.k_IndentWidth; }\n            set { m_GUI.k_IndentWidth = value; }\n        }\n\n        protected bool showAlternatingRowBackgrounds { get; set; }\n        protected bool showBorder { get; set; }\n        protected bool showingHorizontalScrollBar { get { return m_TreeView.showingHorizontalScrollBar; }}\n        protected bool showingVerticalScrollBar { get { return m_TreeView.showingVerticalScrollBar; } }\n        internal bool sortByNameAfterSearch { get; set; } = true;\n","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControl.cs#L196-L232","documentation":"Thrown by GetCellRectForTreeFoldouts when multiColumnHeader is null. The method delegates to multiColumnHeader.GetCellRect to compute the rectangle for the foldout within a specific column, so without a header there is no column geometry to query.","triggerScenarios":"Calling GetCellRectForTreeFoldouts in a row-drawing override on a TreeView that was constructed without a MultiColumnHeader; calling before the header is assigned.","commonSituations":"Overriding OnRowGUI (or similar) and unconditionally calling GetCellRectForTreeFoldouts; sharing draw code between single-column and multi-column TreeView subclasses.","solutions":["Only call GetCellRectForTreeFoldouts when multiColumnHeader != null.","Branch row-drawing logic: use GetCellRectForTreeFoldouts for multi-column, use the full rowRect for single-column.","Construct the TreeView with a MultiColumnHeader if you need column-based cell rects."],"exampleFix":"// before\nprotected override void RowGUI(RowGUIArgs args)\n{\n    var foldoutRect = GetCellRectForTreeFoldouts(args.rowRect);\n    // ...\n}\n\n// after\nprotected override void RowGUI(RowGUIArgs args)\n{\n    var foldoutRect = multiColumnHeader != null\n        ? GetCellRectForTreeFoldouts(args.rowRect)\n        : args.rowRect;\n    // ...\n}","handlingStrategy":"type-guard","validationCode":"Rect foldoutRect = tree.multiColumnHeader != null\n    ? tree.GetCellRectForTreeFoldouts(rowRect)\n    : rowRect;","typeGuard":"static bool CanUseCellRect<T>(TreeView<T> tv) => tv.multiColumnHeader != null;","tryCatchPattern":null,"preventionTips":["Branch row-drawing code based on multiColumnHeader presence.","Construct the TreeView with a MultiColumnHeader if you need cell rects.","Avoid sharing unconditional cell-rect logic across TreeView variants."],"tags":["unity","treeview","multicolumnheader","invalid-operation","row-drawing"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}