Tree View UI Tool Kit

Hello,
I am trying to create a basic hierarchy using UI ToolKit by referring the following unity documentation.
Unity - Manual: Create list and tree views (unity3d.com)

Reference of what I am trying to create: A multi-level hierarchy for a 3D model with UI toolkit at runtime.
9722287--1389853--upload_2024-3-24_20-6-52.png

I was able to create a basic 2 level hierarchy, but I want the children to hold multi-level hierarchy.
9722287--1389859--upload_2024-3-24_20-8-35.png

I tried to change few things, but I am not able to make it a multi-level hierarchy.
Can someone suggest if this is possible by using the same codebase mentioned here Unity - Manual: Create list and tree views (unity3d.com) or do we need a major change.

Thank you.

9722287--1389856--upload_2024-3-24_20-8-8.png

It’s definitely possible. Effectively, when you instantiate your root TreeViewItemData, it will add another two for Mammals and Reptiles as children, and of those will add all the animals as children as well.

Most likely will involve some kind of recursion.

Here’s an example of one I did to show the various parts the player has equipped on their robot (old image):
Image

The data was already in a tree-like structure, so it was a case of writing a single recursive method to build all the elements.

1 Like