Merge pull request #104740 from Jojo-1000/update-import-plugin-docs

Update EditorImportPlugin docs and clarify which methods are required
This commit is contained in:
Thaddeus Crews 2025-10-01 13:12:32 -05:00
commit 0a5f7125e4
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
3 changed files with 61 additions and 79 deletions

View file

@ -124,17 +124,18 @@
<return type="bool" />
<description>
Tells whether this importer can be run in parallel on threads, or, on the contrary, it's only safe for the editor to call it from the main thread, for one file at a time.
If this method is not overridden, it will return [code]false[/code] by default.
If this importer's implementation is thread-safe and can be run in parallel, override this with [code]true[/code] to optimize for concurrency.
If not overridden, returns [code]false[/code].
</description>
</method>
<method name="_get_format_version" qualifiers="virtual const">
<return type="int" />
<description>
Gets the format version of this importer. Increment this version when making incompatible changes to the format of the imported resources.
If not overridden, the format version is [code]0[/code].
</description>
</method>
<method name="_get_import_options" qualifiers="virtual const">
<method name="_get_import_options" qualifiers="virtual required const">
<return type="Dictionary[]" />
<param index="0" name="path" type="String" />
<param index="1" name="preset_index" type="int" />
@ -148,7 +149,7 @@
Gets the order of this importer to be run when importing resources. Importers with [i]lower[/i] import orders will be called first, and higher values will be called later. Use this to ensure the importer runs after the dependencies are already imported. The default import order is [code]0[/code] unless overridden by a specific importer. See [enum ResourceImporter.ImportOrder] for some predefined values.
</description>
</method>
<method name="_get_importer_name" qualifiers="virtual const">
<method name="_get_importer_name" qualifiers="virtual required const">
<return type="String" />
<description>
Gets the unique name of the importer.
@ -189,9 +190,10 @@
<return type="int" />
<description>
Gets the number of initial presets defined by the plugin. Use [method _get_import_options] to get the default options for the preset and [method _get_preset_name] to get the name of the preset.
By default, there are no presets.
</description>
</method>
<method name="_get_preset_name" qualifiers="virtual const">
<method name="_get_preset_name" qualifiers="virtual required const">
<return type="String" />
<param index="0" name="preset_index" type="int" />
<description>
@ -204,31 +206,31 @@
Gets the priority of this plugin for the recognized extension. Higher priority plugins will be preferred. The default priority is [code]1.0[/code].
</description>
</method>
<method name="_get_recognized_extensions" qualifiers="virtual const">
<method name="_get_recognized_extensions" qualifiers="virtual required const">
<return type="PackedStringArray" />
<description>
Gets the list of file extensions to associate with this loader (case-insensitive). e.g. [code]["obj"][/code].
</description>
</method>
<method name="_get_resource_type" qualifiers="virtual const">
<method name="_get_resource_type" qualifiers="virtual required const">
<return type="String" />
<description>
Gets the Godot resource type associated with this loader. e.g. [code]"Mesh"[/code] or [code]"Animation"[/code].
</description>
</method>
<method name="_get_save_extension" qualifiers="virtual const">
<method name="_get_save_extension" qualifiers="virtual required const">
<return type="String" />
<description>
Gets the extension used to save this resource in the [code].godot/imported[/code] directory (see [member ProjectSettings.application/config/use_hidden_project_data_directory]).
</description>
</method>
<method name="_get_visible_name" qualifiers="virtual const">
<method name="_get_visible_name" qualifiers="virtual required const">
<return type="String" />
<description>
Gets the name to display in the import window. You should choose this name as a continuation to "Import as", e.g. "Import as Special Mesh".
</description>
</method>
<method name="_import" qualifiers="virtual const">
<method name="_import" qualifiers="virtual required const">
<return type="int" enum="Error" />
<param index="0" name="source_file" type="String" />
<param index="1" name="save_path" type="String" />

View file

@ -35,39 +35,29 @@
String EditorImportPlugin::get_importer_name() const {
String ret;
if (GDVIRTUAL_CALL(_get_importer_name, ret)) {
GDVIRTUAL_CALL(_get_importer_name, ret);
return ret;
}
ERR_FAIL_V_MSG(String(), "Unimplemented _get_importer_name in add-on.");
}
String EditorImportPlugin::get_visible_name() const {
String ret;
if (GDVIRTUAL_CALL(_get_visible_name, ret)) {
GDVIRTUAL_CALL(_get_visible_name, ret);
return ret;
}
ERR_FAIL_V_MSG(String(), "Unimplemented _get_visible_name in add-on.");
}
void EditorImportPlugin::get_recognized_extensions(List<String> *p_extensions) const {
Vector<String> extensions;
if (GDVIRTUAL_CALL(_get_recognized_extensions, extensions)) {
GDVIRTUAL_CALL(_get_recognized_extensions, extensions);
for (int i = 0; i < extensions.size(); i++) {
p_extensions->push_back(extensions[i]);
}
return;
}
ERR_FAIL_MSG("Unimplemented _get_recognized_extensions in add-on.");
}
String EditorImportPlugin::get_preset_name(int p_idx) const {
String ret;
if (GDVIRTUAL_CALL(_get_preset_name, p_idx, ret)) {
GDVIRTUAL_CALL(_get_preset_name, p_idx, ret);
return ret;
}
ERR_FAIL_V_MSG(itos(p_idx), "Unimplemented _get_preset_name in add-on.");
}
int EditorImportPlugin::get_preset_count() const {
int ret;
@ -79,19 +69,15 @@ int EditorImportPlugin::get_preset_count() const {
String EditorImportPlugin::get_save_extension() const {
String ret;
if (GDVIRTUAL_CALL(_get_save_extension, ret)) {
GDVIRTUAL_CALL(_get_save_extension, ret);
return ret;
}
ERR_FAIL_V_MSG(String(), "Unimplemented _get_save_extension in add-on.");
}
String EditorImportPlugin::get_resource_type() const {
String ret;
if (GDVIRTUAL_CALL(_get_resource_type, ret)) {
GDVIRTUAL_CALL(_get_resource_type, ret);
return ret;
}
ERR_FAIL_V_MSG(String(), "Unimplemented _get_resource_type in add-on.");
}
float EditorImportPlugin::get_priority() const {
float ret;
@ -120,7 +106,7 @@ int EditorImportPlugin::get_format_version() const {
void EditorImportPlugin::get_import_options(const String &p_path, List<ResourceImporter::ImportOption> *r_options, int p_preset) const {
Array needed = { "name", "default_value" };
TypedArray<Dictionary> options;
if (GDVIRTUAL_CALL(_get_import_options, p_path, p_preset, options)) {
GDVIRTUAL_CALL(_get_import_options, p_path, p_preset, options);
for (int i = 0; i < options.size(); i++) {
Dictionary d = options[i];
ERR_FAIL_COND(!d.has_all(needed));
@ -145,10 +131,6 @@ void EditorImportPlugin::get_import_options(const String &p_path, List<ResourceI
ImportOption option(PropertyInfo(default_value.get_type(), name, hint, hint_string, usage), default_value);
r_options->push_back(option);
}
return;
}
ERR_FAIL_MSG("Unimplemented _get_import_options in add-on.");
}
bool EditorImportPlugin::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
@ -176,7 +158,7 @@ Error EditorImportPlugin::import(ResourceUID::ID p_source_id, const String &p_so
}
Error err = OK;
if (GDVIRTUAL_CALL(_import, p_source_file, p_save_path, options, platform_variants, gen_files, err)) {
GDVIRTUAL_CALL(_import, p_source_file, p_save_path, options, platform_variants, gen_files, err);
for (int i = 0; i < platform_variants.size(); i++) {
r_platform_variants->push_back(platform_variants[i]);
}
@ -185,8 +167,6 @@ Error EditorImportPlugin::import(ResourceUID::ID p_source_id, const String &p_so
}
return err;
}
ERR_FAIL_V_MSG(ERR_METHOD_NOT_FOUND, "Unimplemented _import in add-on.");
}
bool EditorImportPlugin::can_import_threaded() const {
bool ret = false;

View file

@ -39,19 +39,19 @@ class EditorImportPlugin : public ResourceImporter {
protected:
static void _bind_methods();
GDVIRTUAL0RC(String, _get_importer_name)
GDVIRTUAL0RC(String, _get_visible_name)
GDVIRTUAL0RC_REQUIRED(String, _get_importer_name)
GDVIRTUAL0RC_REQUIRED(String, _get_visible_name)
GDVIRTUAL0RC(int, _get_preset_count)
GDVIRTUAL1RC(String, _get_preset_name, int)
GDVIRTUAL0RC(Vector<String>, _get_recognized_extensions)
GDVIRTUAL2RC(TypedArray<Dictionary>, _get_import_options, String, int)
GDVIRTUAL0RC(String, _get_save_extension)
GDVIRTUAL0RC(String, _get_resource_type)
GDVIRTUAL1RC_REQUIRED(String, _get_preset_name, int)
GDVIRTUAL0RC_REQUIRED(Vector<String>, _get_recognized_extensions)
GDVIRTUAL2RC_REQUIRED(TypedArray<Dictionary>, _get_import_options, String, int)
GDVIRTUAL0RC_REQUIRED(String, _get_save_extension)
GDVIRTUAL0RC_REQUIRED(String, _get_resource_type)
GDVIRTUAL0RC(float, _get_priority)
GDVIRTUAL0RC(int, _get_import_order)
GDVIRTUAL0RC(int, _get_format_version)
GDVIRTUAL3RC(bool, _get_option_visibility, String, StringName, Dictionary)
GDVIRTUAL5RC(Error, _import, String, String, Dictionary, TypedArray<String>, TypedArray<String>)
GDVIRTUAL5RC_REQUIRED(Error, _import, String, String, Dictionary, TypedArray<String>, TypedArray<String>)
GDVIRTUAL0RC(bool, _can_import_threaded)
Error _append_import_external_resource(const String &p_file, const Dictionary &p_custom_options = Dictionary(), const String &p_custom_importer = String(), Variant p_generator_parameters = Variant());