Can't Create Child Tree Item On "item_collapsed" Signal

Godot Version



I attempt to attach additional child tree items to a parent tree item when the parent expands(i.e. “item_collapsed”). But I get the error: scene/gui/tree.cpp:4291 - Condition "blocked > 0" is true. Returning: nullptr.

Does this mean it’s not possible?

“item_collapsed” Callback

func _on_tree_item_collapsed(item: TreeItem):
	var metadata = item.get_metadata(0)
	var should_attach_leaf_items = \
		typeof(metadata) != TYPE_NIL \
		&& item.collapsed == false \
		&& metadata["processed"] == false
	if should_attach_leaf_items:
		metadata["processed"] = true
		item.set_metadata(0, metadata)
		attach_leaf_tree_items(global_tree, item, metadata)

Section from “attach_leaf_tree_items” where “create_item” attempted

func attach_leaf_tree_items(tree: Tree, parent: TreeItem, definition: Dictionary):
	var variants = get_variants(definition)
	# This is for all variants after "None"
	for variant in variants:
		var item = tree.create_item(parent)

It may not let you at the same time. Try with call_deferred():

attach_leaf_tree_items.call_deferred(global_tree, item, metadata)

That worked, @mrcdk ! No more “blocked” errors. You made my day :slightly_smiling_face: !! I didn’t think it was going to be possible to add more child tree items on parent tree item expansion.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.