{"record":{"id":"03be37d2d376b78e","repo":"Unity-Technologies/UnityCsReference","slug":"invalid-index-for-columnindexfortreefoldouts-0","errorCode":null,"errorMessage":"Invalid index for columnIndexForTreeFoldouts: {0}. Number of available columns: {1}","messagePattern":"Invalid index for columnIndexForTreeFoldouts: (.+?)\\. Number of available columns: (.+?)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControl.cs","lineNumber":199,"sourceCode":"            set { m_GUI.extraSpaceBeforeIconAndLabel = value; }\n        }\n\n        protected float customFoldoutYOffset\n        {\n            get { return m_GUI.customFoldoutYOffset; }\n            set { m_GUI.customFoldoutYOffset = value; }\n        }\n\n        protected int columnIndexForTreeFoldouts\n        {\n            get { return m_GUI.columnIndexForTreeFoldouts; }\n            set\n            {\n                if (multiColumnHeader == null)\n                    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);","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControl.cs#L181-L217","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ntree.columnIndexForTreeFoldouts = 3; // header only has 2 columns\n\n// after\nint max = header.state.columns.Length;\ntree.columnIndexForTreeFoldouts = Mathf.Clamp(3, 0, max - 1);","handlingStrategy":"validation","validationCode":"int max = header.state.columns.Length;\nint idx = Mathf.Clamp(desiredIndex, 0, max - 1);\ntree.columnIndexForTreeFoldouts = idx;","typeGuard":"static bool IsValidColumnIndex(int idx, MultiColumnHeader h) => idx >= 0 && idx < h.state.columns.Length;","tryCatchPattern":null,"preventionTips":["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."],"tags":["unity","treeview","argument-out-of-range","multicolumnheader","foldout"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}