Manually triggering a reimport via an EditorScript results in progress_dialog errors

Godot Version

4.5

Question

There is a custom EditorImportPlugin on a file that I want to manually trigger via an EditorScript.

The script is very simple and I’m running it via the Command Palette:

@tool
class_name ImportLdtkCmd

extends EditorScript

func _run():
    var file_system = EditorInterface.get_resource_filesystem()
    file_system.reimport_files(["res://mimic_ldtk/mimic.ldtk"])

The reimport is successful but I’m getting these errors when I run it. Any ideas on how I can prevent them?

 ERROR: editor/gui/progress_dialog.cpp:191 - Do not use progress dialog (task) while flushing the message queue or using call_deferred()!
  ERROR: editor/gui/progress_dialog.cpp:225 - Condition "!tasks.has(p_task)" is true. Returning: canceled
  ERROR: editor/gui/progress_dialog.cpp:225 - Condition "!tasks.has(p_task)" is true. Returning: canceled
  ERROR: editor/gui/progress_dialog.cpp:191 - Do not use progress dialog (task) while flushing the message queue or using call_deferred()!

Did you try using Callable.call_deferred() in the reimport_files() function?

I can’t use call_deferred on the EditorScript because it never executes.

If you use the editor tree then I can’t access my function:

func _run():
    var tree = Engine.get_main_loop() as SceneTree
    tree.call_deferred("reimport")
    
func reimport():
    print("reimport")
    var file_system = EditorInterface.get_resource_filesystem()
    file_system.reimport_files(["res://mimic_ldtk/mimic.ldtk"])
 ERROR: core/object/message_queue.cpp:222 - Error calling deferred method: 'SceneTree::reimport': Method not found.

:thinking:

What do you mean it never executes? Did you do it like: file_system.reimport_files.call_deferred(["res://..."])?

This makes sense, the SceneTree does not have a reimport() function, your script does.

Oh i didn’t realize you can use call_deferred that way! Thanks

Still throws the error tho :confused:

func _run():
    var file_system = EditorInterface.get_resource_filesystem()
    file_system.reimport_files.call_deferred(["res://mimic_ldtk/mimic.ldtk"])
  ERROR: editor/gui/progress_dialog.cpp:191 - Do not use progress dialog (task) while flushing the message queue or using call_deferred()!
  ERROR: editor/gui/progress_dialog.cpp:225 - Condition "!tasks.has(p_task)" is true. Returning: canceled
  ERROR: editor/gui/progress_dialog.cpp:225 - Condition "!tasks.has(p_task)" is true. Returning: canceled

What are you exactly doing? What does the EditorImportPlugin do? Why do you need to force a manual re-import of those files with an EditorScript?

I’m using a plugin to import data from an ldtk file. Here is the EditorImportPlugin that I’m trying to trigger: godot-ldtk-importer/addons/ldtk-importer/ldtk-importer.gd at main · heygleeson/godot-ldtk-importer · GitHub

I’m trying to speed up my workflow by using a command palette to import on demand. It’s annoying to always have to select the asset, go to the import tab and click “reimport”:

Isn’t the Resource re-importing after tabbing back to Godot? I tried using that plugin and its example ldtk file and the Resource is being re-imported every time I go back to Godot.

Either way, this should stop those errors:

func _run() -> void:
	var root = EditorInterface.get_base_control()
	root.get_tree().process_frame.connect(func():
		var file_system = EditorInterface.get_resource_filesystem()
		file_system.reimport_files(["res://mimic_ldtk/mimic.ldtk"])
	, CONNECT_ONE_SHOT)
2 Likes

Thanks so much! That worked

Yeah i know it’s supposed to refresh when you tab back but sometimes it doesnt so I needed a backup. :person_shrugging:

@mrcdk this is why i needed this tool: Auto re-import doesn't work when you just change tiles · Issue #61 · heygleeson/godot-ldtk-importer · GitHub

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