Can TreeItems hold Control-nodes?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Olaf007

I have this basic tutorial script from the documentation…

func _ready():
    var tree = Tree.new()
    var root = tree.create_item() # Here the 1st TreeItem is returned to root 
    tree.set_hide_root(true)
    var child1 = tree.create_item(root)
    var child2 = tree.create_item(root)
    var subchild1 = tree.create_item(child1)

The TreeItem inherits from Object and not from Node so I suppose I cannot add a custom Control node (and its children) to the tree!?
Wouldn’t this be a useful feature? :slight_smile:

:bust_in_silhouette: Reply From: Zylann

No, TreeItem is an Object, which is only meant to hold some data about the item.

There are a few options on tree items which allow them to look different: TreeItem — Godot Engine (stable) documentation in English
And other options can be found in the same doc.

If you need full-fledged controls it might require to make a different node, Tree is really not designed to hold controls like that (and won’t yield the same performance with many items). You might be able to get away with expander buttons and VBoxContainer nodes maybe, like the inspector appears to do.

Thank you! This cleared up my doubts. :))

Olaf007 | 2020-09-11 15:45