+2 votes

According to the doc

  • Add a custom menu to 'Project > Tools' as name that calls callback on
    an instance of handler with a parameter ud when user activates it.

so I have the following code

extends EditorPlugin

var test_obj = load("res://addons/Add_item_to_tool/tool_test_ui.tscn")
var instanced_ui = null 
func _enter_tree():


func _exit_tree():

func instance_ui():
    instanced_ui = load("res://addons/Add_item_to_tool/tool_test_ui.tscn").instance()

if I understand it correctly . I need a string name for the menu, and a obj and a fcuntion to call when I click on the menu. But I am getting
editor/editor_node.cpp:2437 - Error calling function from tool menu: 'PackedScene::instance_ui': Method not found.
I am not sure how to use this, and there doesn't seem to have any example on it

in Engine by (168 points)

1 Answer

+1 vote
Best answer

So, I have also been looking into how to add items to the Project/Tool menu. So far I have found that:

  1. The Object add_tool_menu_item takes must be loaded from a
    script. In other words, loading a scene (as far as I know) will not

  2. The object passed to add_tool_menu_item must have the function

Here's an example add_tool_mean_item being used to fire a method and display a file popup:

extends EditorPlugin

var popup
func _enter_tree():
    popup = FileDialog.new()
    add_tool_menu_item("Test", self, "callback")
    # add_import_plugin(import_plugin)

func callback(ud): 

func _exit_tree():

You add your GUI items to the editor once your callback method has been fired using add_child.

by (62 points)
selected by

Thanks, this works. I now just need to implement this into my tool

Also use get_editor_interface().get_base_control().add_child instead of just add_child. You GUI elements will automatically inherit the current editor them get_editor_interface().get_base_control().add_child.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.