I have a dynamically built tree node that will have a variable number of items, and I want each item to have a button. I connected the button_clicked signal to the tree, which auto-generated a receiver function. The code below will produce a tree with all the correct levels and text, but no buttons and the following error:
E 0:00:01:380 year_end_control.gd:49 @ build_policy_tree(): Condition "p_button.is_null()" is true.
<C++ Source> scene/gui/tree.cpp:1335 @ add_button()
<Stack Trace> year_end_control.gd:49 @ build_policy_tree()
year_end_control.gd:16 @ _ready()
func build_policy_tree(year: int, pol_set : Array):
if year != 10:
var root = policy_tree.create_item()
root.set_text(0, "Policies")
for policy in pol_set:
var sectionX = policy_tree.create_item(root)
sectionX.set_text(0, (policy.get("title")))
var choicesX = policy.get("choices")
for choiceX in choicesX:
var itemX = policy_tree.create_item(sectionX)
itemX.set_text(0, choicesX[choiceX])
itemX.add_button(1, $PolicyTree/tree_button_image)
func _on_policy_tree_button_clicked() -> void:
print("tree button pressed")
I tried using the get_button_count() function on itemX below the add_button() line, and this always returns 0, so I understand that the button isn't being created but I don't know why.