Godot Version
v4.3.stable.official [77dcf97d8]
Question
I’m writing an editor plugin. I’m dynamically building a toolbar which involves iterating over the child nodes of a ‘menu’ node and creating a button control for each one of them. Since my custom button requires the path to the node that the button references, I’m calling get_path()
on each of the nodes when it iterate over the children.
Unfortunately, this is resulting in the Cannot get path of node as it is not in a scene tree
error being printed to console. The node with the children is being added as a child of the root plugin node. I’ve tried calling is_node_ready()
and is_inside_tree()
on the children when I build the buttons, but I’m still getting the error. I seem to be getting correct paths despite the error, since I can use them to find the original nodes.
What can I do to avoid this error?
var menu_root = editor_plugin.config_scene.get_node("Views/View3D/Toolbar")
for child in menu_root.get_children():
if child is ToolbarButtonRef:
var tool:CyclopsTool = child.tool
if tool.is_inside_tree() && tool._show_in_toolbar() && tool._can_handle_object(active_block):
var bn:ToolButton = preload("res://addons/cyclops_level_builder/gui/menu/tool_button.tscn").instantiate()
bn.tool_path = tool.get_path()
...