This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I am trying to add some items onto the Tree Control.

I have Tree control in my Project

In Script attached to main root I have this. (this is all i have for code
No errors either... but it doesn't show anything in the tree.

What am i doing wrong.

extends Node2D
func _ready():
    var tree = Tree.new()
    tree.set_hide_root(false)
    var root = tree.create_item()
    root.set_text(0, "Root")
    var child1 = tree.create_item(root)
    child1.set_text(0, "Child 1")
    var child2 = tree.create_item(root)
    child2.set_text(0, "Child 2")
    var subchild1 = tree.create_item(child1)
    subchild1.set_text(0, "Subchild 1")
    var subchild2 = tree.create_item(child1)
    subchild2.set_text(0, "Subchild 2")
in Engine by (54 points)

1 Answer

+1 vote
Best answer

I figured it out....
I forgot to include the parent control for the tree (a main panel)

extends Node2D
func _ready():
    var tree = Tree.new()
    var root = $Interface/Tree.create_item()
    root.set_text(0,"Root")
    var child1 = $Interface/Tree.create_item(root)
    child1.set_text(0, "Child 1")
    var child2 = $Interface/Tree.create_item(root)
    child2.set_text(0, "Child 2")
    var subchild1 = $Interface/Tree.create_item(child1)
    subchild1.set_text(0, "Subchild 1")
    var subchild2 = $Interface/Tree.create_item(child1)
    subchild2.set_text(0, "Subchild 2")
by (54 points)
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.