- Edited
Hello their! I am Oolks! I want to recreate the hierarchy of nodes like this:
In runtime, I decided to use the tree node but, it is unable to show me the childrens and the grand childrens (and so on) of an object. It works as:
extends Tree
var selected_item: Node
func _ready() -> void:
create_tree_items(get_tree().get_root().get_node("index/Level"), self.create_item(self))
func create_tree_items(node: Node, item: TreeItem) -> void:
for child_index in range(node.get_child_count()):
var child = node.get_child(child_index)
if child.get_name() == "":
continue
var child_item = self.create_item(item)
child_item.set_text(0, child.get_name())
create_tree_items_recursive(child, child_item)
func create_tree_items_recursive(node: Node, item: TreeItem) -> void:
for child_index in range(node.get_child_count()):
var child = node.get_child(child_index)
if child.get_name() == "":
continue
var child_item = self.create_item(item)
child_item.set_text(0, child.get_name())
if child.get_child_count() > 0:
create_tree_items_recursive(child, child_item)
func _on_Objects_child_entered_tree(node):
pass # Replace with function body.
Whenever the _on_Objects_child_entered_tree
is fired (signal) it creates a new tree item which has no parent meaning if its a children of an object, it wont show as a children of the object in the tree.