In the 2d mainscreen (layout) the tree-items display if I generate them in _ready

I don't know quite how to puzzle this out. I've added a button to the scene and it presents and operates fine. I even use it to generate tree-items but they do not show.

I would appreciate any tips on debugging stuff like this or some documentation clarifying the rules of the road

// Editor.gd
tool extends VBoxContainer

var tree_ : Tree
var button_ : Button

func _ready():
	button_ = get_node("Welcome") as Button
	tree_ = get_node("HBoxContainer/Tree") as Tree

func _on_Welcome_button_down():
	print("hello tree")
	if tree_ == null :
		print("no tree_")
	else:
		var root = tree_.create_item()
		var child1 = tree_.create_item(root)
		var child2 = tree_.create_item(root)
		var subchild1 = tree_.create_item(child1)
		child1.set_text(0, "Child1")
		child2.set_text(0, "Child2")
		subchild1.set_text(0, "Subchild1")

//plugin.gd
tool
extends EditorPlugin

const MainPanel = preload("res://addons/Editor/Editor.tscn")

var main_

func _enter_tree():
	main_ = MainPanel.instance()
	get_editor_interface().get_editor_viewport().add_child(main_)
	make_visible(false)

func _exit_tree():
	if main_:
		main_.queue_free()

func _ready():
	pass

func has_main_screen():
	return true

func make_visible(visible):
	print("make_visible")
	if main_:
		main_.visible = visible

func get_plugin_name():
	return "MyEditor"

func get_plugin_icon():
	return get_editor_interface().get_base_control().get_icon("Node", "EditorIcons")

// editor.tscn
[gd_scene load_steps=4 format=2]

[ext_resource path="res://addons/PsycheEditor/Editor.gd" type="Script" id=1]

[sub_resource type="Theme" id=1]

[sub_resource type="StyleBoxFlat" id=2]
bg_color = Color( 0.376471, 0.192157, 0.192157, 1 )

[node name="Editor" type="VBoxContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 92.0
margin_top = 27.0
margin_right = 92.0
margin_bottom = 27.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Welcome" type="Button" parent="."]
margin_right = 1024.0
margin_bottom = 20.0
text = "If you want to know more."

[node name="Tree" type="Tree" parent="HBoxContainer"]
margin_right = 1024.0
margin_bottom = 576.0
size_flags_horizontal = 3
size_flags_vertical = 3
theme = SubResource( 1 )
custom_styles/bg = SubResource( 2 )
allow_reselect = true
[connection signal="button_down" from="Welcome" to="." method="_on_Welcome_button_down"]

This is boiling down to a simpler question how the heck do you tell or make a tree fill its container?

By sticking a theme and hacking in a red background it is obvious that the tree node is taking no space. As much as I have searched there does not seem to be any documentation on how the godot layout engine works.

Have you programmed the tree node to have content? It's a bit of a special case where you can't really fill it by giving it children in the editor I'm afraid.

edit: formatted the OP. And I see that you do add children in the script. I'll try and see if tomorrow I can locate an older project I have somewhere that I know I had set up a treenode that was working. Getting too late for me today though.

I took the scene and ran it as a the main scene as a 'game'. The tree fills its container, matching the layout presented in 2D editor, which consistently shows the tree itself expanding to fill space (i've muddled around with combinations of v and h box containers).

If you add items in the _prepare method, the 2D editor even shows those items in its own view, yet the tree remains stubbornly sized differently as when instantiated as a scene for a main_screen.

If I place a button along with it in a h-box, then the tree dutifully occupies the height of the button and the remaining horizontal space in the main_screen.

The issue seems to be that main_screen layout works differently than in 'game' mode, therefore running the scene as a game is not a viable avenue of debugging.

--edit--

by placing various shims around (now item-list) i can see items in the list, but the list like tree is not filling its container. This is strictly a layout issue and nothing else. However, it is immensely draining to be pawing around in the dark like this.

I threw out the old code and in a new editor tab made the following which works for item list. The button is connected to _on_Welcome_button_down().

//  gd
tool
extends VBoxContainer

var list_ : ItemList
var button_ : Button

# Called when the node enters the scene tree for the first time.
func _ready():
	button_ = get_node("Welcome") as Button
	list_ = get_node("ItemList") as ItemList

func _on_Welcome_button_down():
	print("hello tree")
	if list_ == null :
		print("no stucture_")
	else:
		list_.add_item("hi")

// tscn
[gd_scene load_steps=3 format=2]

[ext_resource path="res://addons/PsycheEditor/Editor.gd" type="Script" id=1]
[ext_resource path="res://addons/PsycheEditor/Editor.tres" type="Theme" id=2]

[node name="Editor" type="VBoxContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
size_flags_vertical = 3
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Welcome" type="Button" parent="."]
margin_right = 1024.0
margin_bottom = 20.0
text = "welcom"

[node name="ItemList" type="ItemList" parent="."]
margin_top = 24.0
margin_right = 1024.0
margin_bottom = 600.0
size_flags_horizontal = 3
size_flags_vertical = 3
theme = ExtResource( 2 )
[connection signal="button_down" from="Welcome" to="." method="_on_Welcome_button_down"]

Ah, sounds like your issue is something else from what I previously interpreted. Alas, I don't know how to solve that unless the post just above solved it?

I decided to open a blank project and replace item list with tree. It works fine with a simple vbox/tree. Pushed code back into the real project. Works fine.

I guess it only means if things act funny, restart the editor (and try a stripped down example first). At least it will clarify if there actually is a problem or not.

3 years later