{"record":{"id":"ea8d3f3c43239d7d","repo":"Unity-Technologies/UnityCsReference","slug":"finditem-failed-root-item-has-not-been-created-ye","errorCode":null,"errorMessage":"FindItem failed: root item has not been created yet","messagePattern":"FindItem failed: root item has not been created yet","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControl.cs","lineNumber":608,"sourceCode":"            return parentsAbove.ToArray();\n#pragma warning restore UA2001\n        }\n\n        // Used to expand children recursively below an item\n        protected virtual IList<TIdentifier> GetDescendantsThatHaveChildren(TIdentifier id)\n        {\n            // Default behavior assumes complete tree\n            HashSet<TIdentifier> parentsBelow = new HashSet<TIdentifier>();\n            TreeViewUtility<TIdentifier>.GetParentsBelowItem(FindItem(id), parentsBelow);\n#pragma warning disable UA2001 // The Banned API Analyzer produces compile errors for any new Linq code. This pre-existing usage has been suppressed, but should be rewritten if possible.\n            return parentsBelow.ToArray();\n#pragma warning restore UA2001\n        }\n\n        TreeViewItem<TIdentifier> FindItem(TIdentifier id)\n        {\n            if (rootItem == null)\n                throw new InvalidOperationException(\"FindItem failed: root item has not been created yet\");\n\n            return TreeViewUtility<TIdentifier>.FindItem(id, rootItem);\n        }\n\n        // Selection\n        protected virtual bool CanMultiSelect(TreeViewItem<TIdentifier> item) => CanMultiSelectInternal(item);\n\n        internal virtual bool CanMultiSelectInternal(TreeViewItem<TIdentifier> item)\n        {\n            return true; // default behavior\n        }\n\n        // Renaming\n        protected virtual bool CanRename(TreeViewItem<TIdentifier> item) => CanRenameInternal(item);\n\n        internal virtual bool CanRenameInternal(TreeViewItem<TIdentifier> item)\n        {\n            return false; // Default to false so user have to enable renaming if wanted","sourceCodeStart":590,"sourceCodeEnd":626,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControl.cs#L590-L626","documentation":"Thrown by FindItem (a private helper used by GetAncestors and GetDescendantsThatHaveChildren) when rootItem is null. FindItem traverses the tree starting from rootItem to locate an item by id; without a root the tree has not been built and the search is invalid.","triggerScenarios":"Calling GetParentsBelow or related methods that invoke FindItem before BuildRoot/Reload has populated rootItem; BuildRoot returned null on the previous fetch.","commonSituations":"Calling GetAncestors/GetDescendantsThatHaveChildren in a custom override before the data source has built the tree; calling these methods right after construction without Reload.","solutions":["Ensure treeView.Reload() has been called so rootItem is populated before any id-based lookup.","Override BuildRoot to always return a valid root item.","Avoid calling GetAncestors/GetDescendantsThatHaveChildren during the initial BuildRoot call itself."],"exampleFix":"// before\nvar parents = treeView.GetParentsBelow(someId); // rootItem null\n\n// after\ntreeView.Reload();\nvar parents = treeView.GetParentsBelow(someId);","handlingStrategy":"validation","validationCode":"treeView.Reload();\n// rootItem is now populated; FindItem-based calls are safe","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call Reload before GetAncestors/GetDescendantsThatHaveChildren.","Ensure BuildRoot returns a non-null root so rootItem is set.","Do not call id-lookup methods during initial BuildRoot."],"tags":["unity","treeview","invalid-operation","buildroot","finditem"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}