0 votes

My script:

extends EditorPlugin

func _enter_tree():
    # Initialization of the plugin goes here
    add_tool_menu_item('Find Texture Borders', self, '_do_work')

func _do_work(ud):
    var res_path = ?? # res://themes/288dpi/yellow_button00.png
    var texture = load(res_path)

I need something like a FileDialog that works in EditorScript and returns a path inside my project's file system.

in Engine by (21 points)

1 Answer

+1 vote
Best answer

You must use a FileDialog node. When using plugins, dialogs must be child of a specific node called the "base control", I think it's what makes them take the editor theme as well. Then signals are used.

var _file_dialog

func _enter_tree():

    add_tool_menu_item('Find Texture Borders', self, '_do_work')

    _file_dialog = FileDialog.new()
    _file_dialog.mode = FileDialog.MODE_OPEN_FILE
    _file_dialog.access = FileDialog.ACCESS_RESOURCES
    # ... more config
    _file_dialog.connect("file_selected", self, "_on_FileDialog_file_selected")

    var editor_interface = get_editor_interface()
    var base_control = editor_interface.get_base_control()

    # Other setup code...

func _exit_tree():

    # Cleanup

func _do_work(ud):

func _on_FileDialog_file_selected(path):
    var texture = load(res_path)
    # Continue work using selected path
by (28,882 points)
selected by

Worked perfectly! I could never have done it alone!

I was curious about the nomenclature you used in "filedialog", I think I will adopt. Where did you see?

I tried to implement this to my program, and Godot told me that get_editor_interface isn't defined. I did some searching and found that it can only be used if you're using plugins. Do you need plugins to let the user upload files to the exported product, or can it be done without them? If you need them, how do you implement them, and what exactly do you need? Could you please point me to some tutorials where i could start? I tried to look something up, but it's all very confusing, i have no idea where to start...

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 Frequently asked questions and 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 [email protected] with your username.