Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import options not working on EditorImportPlugin subclass #470

Open
sekimondre opened this issue May 14, 2024 · 1 comment
Open

Import options not working on EditorImportPlugin subclass #470

sekimondre opened this issue May 14, 2024 · 1 comment

Comments

@sekimondre
Copy link
Contributor

Environment

  • Godot v4.2.2.stable.official
  • macOS 14.4.1
  • swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)

Bug Description

Import options are not working as intended for Import plugins written in Swift. These are the options provided through the _getImportOptions(path:_, presetIndex:_) method of a EditorImportPlugin. The noticeable effects are:

  1. Import options don't show up in the editor's "Import" dock.
  2. An empty dictionary { } is received through the options parameter of the _import(sourceFile:_,savePath:_,options:_,platformVariants:_, genFiles:_) method.

How to reproduce

  1. Create an EditorImportPlugin subclass:
@Godot(.tool)
class TestPlugin: EditorImportPlugin {}
  1. Override and provide a default implementation to all necessary methods.

    • _getImporterName
    • _getVisibleName
    • _getRecognizedExtensions
    • _getResourceType
    • _getSaveExtension
    • _getImportOrder
    • _getPriority
    • _getPresetCount
    • _getPresetName
  2. Override _getImportOptions:

override func _getImportOptions(
    path: String,
    presetIndex: Int32
) -> VariantCollection<GDictionary> {
    let opt1 = GDictionary()
    opt1["name"] = Variant("use_this_option")
    opt1["default_value"] = Variant(false)
    let opt2 = GDictionary()
    opt2["name"] = Variant("another_option")
    opt2["default_value"] = Variant(true)
    return [
        opt1,
        opt2
    ]
}
  1. Override the _import function. Try to print the options parameter or any values that should be in the dictionary.

  2. Create a Godot plugin in res://addons, provide a plugin.cfg file, and enable the import plugin with a GDScript:

@tool
extends EditorPlugin

var plugin: TestPlugin

func _get_plugin_name() -> String:
	return "Test Importer"

func _enter_tree():
	plugin = TestPlugin.new()
	add_import_plugin(plugin)

func _exit_tree():
	remove_import_plugin(plugin)
	plugin = null

Finally, build the library, reload the editor, and enable the plugin on the "Project Settings...". Select a file on the editor's filesystem with the plugin's recognizable extension and open the "Import" tab. Check that no options are shown.

Press the "Reimport" button to trigger an import and check for any values you tried to print to the console.

Considerations

I tried writing the exact same plugin (same values, same overrides, ...) in GDScript and it works. Options show as intended.

Sometimes, options from another import plugin used leak into the _import call (visible by printing to console). Seems like some caching behavior is happening in the editor across plugins.

If someone can make it work is Swift, let me know.

Reference

For more information on Import plugins options, refer to the official documentation:
https://docs.godotengine.org/en/stable/tutorials/plugins/editor/import_plugins.html#options-and-presets

@migueldeicaza
Copy link
Owner

migueldeicaza commented May 14, 2024

Can you annotate the overwritten method with @Callable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants