EditorImportPlugin

Inherits:ResourceImporter<RefCounted<Object

Registers a custom resource importer in the editor. Use the class to parse any file and import it as a new resource type.

Description

EditorImportPlugins provide a way to extend the editor's resource import functionality. Use them to import resources from custom files or to provide alternatives to the editor's existing importers.

EditorImportPlugins work by associating with specific file extensions and a resource type. See_get_recognized_extensions() and_get_resource_type(). They may optionally specify some import presets that affect the import process. EditorImportPlugins are responsible for creating the resources and saving them in the.godot/imported directory (seeProjectSettings.application/config/use_hidden_project_data_directory).

Below is an example EditorImportPlugin that imports aMesh from a file with the extension ".special" or ".spec":

@toolextendsEditorImportPluginfunc_get_importer_name():return"my.special.plugin"func_get_visible_name():return"Special Mesh"func_get_recognized_extensions():return["special","spec"]func_get_save_extension():return"mesh"func_get_resource_type():return"Mesh"func_get_preset_count():return1func_get_preset_name(preset_index):return"Default"func_get_import_options(path,preset_index):return[{"name":"my_option","default_value":false}]func_import(source_file,save_path,options,platform_variants,gen_files):varfile=FileAccess.open(source_file,FileAccess.READ)iffile==null:returnFAILEDvarmesh=ArrayMesh.new()# Fill the Mesh with data read in "file", left as an exercise to the reader.varfilename=save_path+"."+_get_save_extension()returnResourceSaver.save(mesh,filename)

To useEditorImportPlugin, register it using theEditorPlugin.add_import_plugin() method first.

Tutorials

Methods

bool

_can_import_threaded()virtualconst

int

_get_format_version()virtualconst

Array[Dictionary]

_get_import_options(path:String, preset_index:int)virtualconst

int

_get_import_order()virtualconst

String

_get_importer_name()virtualconst

bool

_get_option_visibility(path:String, option_name:StringName, options:Dictionary)virtualconst

int

_get_preset_count()virtualconst

String

_get_preset_name(preset_index:int)virtualconst

float

_get_priority()virtualconst

PackedStringArray

_get_recognized_extensions()virtualconst

String

_get_resource_type()virtualconst

String

_get_save_extension()virtualconst

String

_get_visible_name()virtualconst

Error

_import(source_file:String, save_path:String, options:Dictionary, platform_variants:Array[String], gen_files:Array[String])virtualconst

Error

append_import_external_resource(path:String, custom_options:Dictionary = {}, custom_importer:String = "", generator_parameters:Variant = null)


Method Descriptions

bool_can_import_threaded()virtualconst🔗

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 returnfalse by default.

If this importer's implementation is thread-safe and can be run in parallel, override this withtrue to optimize for concurrency.


int_get_format_version()virtualconst🔗

Gets the format version of this importer. Increment this version when making incompatible changes to the format of the imported resources.


Array[Dictionary]_get_import_options(path:String, preset_index:int)virtualconst🔗

Gets the options and default values for the preset at this index. Returns an Array of Dictionaries with the following keys:name,default_value,property_hint (optional),hint_string (optional),usage (optional).


int_get_import_order()virtualconst🔗

Gets the order of this importer to be run when importing resources. Importers withlower 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 is0 unless overridden by a specific importer. SeeImportOrder for some predefined values.


String_get_importer_name()virtualconst🔗

Gets the unique name of the importer.


bool_get_option_visibility(path:String, option_name:StringName, options:Dictionary)virtualconst🔗

This method can be overridden to hide specific import options if conditions are met. This is mainly useful for hiding options that depend on others if one of them is disabled.

func_get_option_visibility(option,options):# Only show the lossy quality setting if the compression mode is set to "Lossy".ifoption=="compress/lossy_quality"andoptions.has("compress/mode"):returnint(options["compress/mode"])==COMPRESS_LOSSY# This is a constant that you setreturntrue

Returnstrue to make all options always visible.


int_get_preset_count()virtualconst🔗

Gets the number of initial presets defined by the plugin. Use_get_import_options() to get the default options for the preset and_get_preset_name() to get the name of the preset.


String_get_preset_name(preset_index:int)virtualconst🔗

Gets the name of the options preset at this index.


float_get_priority()virtualconst🔗

Gets the priority of this plugin for the recognized extension. Higher priority plugins will be preferred. The default priority is1.0.


PackedStringArray_get_recognized_extensions()virtualconst🔗

Gets the list of file extensions to associate with this loader (case-insensitive). e.g.["obj"].


String_get_resource_type()virtualconst🔗

Gets the Godot resource type associated with this loader. e.g."Mesh" or"Animation".


String_get_save_extension()virtualconst🔗

Gets the extension used to save this resource in the.godot/imported directory (seeProjectSettings.application/config/use_hidden_project_data_directory).


String_get_visible_name()virtualconst🔗

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".


Error_import(source_file:String, save_path:String, options:Dictionary, platform_variants:Array[String], gen_files:Array[String])virtualconst🔗

Importssource_file intosave_path with the importoptions specified. Theplatform_variants andgen_files arrays will be modified by this function.

This method must be overridden to do the actual importing work. See this class' description for an example of overriding this method.


Errorappend_import_external_resource(path:String, custom_options:Dictionary = {}, custom_importer:String = "", generator_parameters:Variant = null)🔗

This function can only be called during the_import() callback and it allows manually importing resources from it. This is useful when the imported file generates external resources that require importing (as example, images). Custom parameters for the ".import" file can be passed via thecustom_options. Additionally, in cases where multiple importers can handle a file, thecustom_importer can be specified to force a specific one. This function performs a resource import and returns immediately with a success or error code.generator_parameters defines optional extra metadata which will be stored asgenerator_parameters in theremap section of the.import file, for example to store a md5 hash of the source data.


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.