+3 votes

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 
    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? :)

in Engine by (52 points)

1 Answer

+4 votes
Best answer

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: https://docs.godotengine.org/en/stable/classes/class_treeitem.html#enum-treeitem-treecellmode
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.

by (29,088 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.