Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

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 (see ProjectSettings.application/config/use_hidden_project_data_directory).

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

@tool
extends EditorImportPlugin

func _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():
    return 1

func _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):
    var file = FileAccess.open(source_file, FileAccess.READ)
    if file == null:
        return FAILED
    var mesh = ArrayMesh.new()
    # Fill the Mesh with data read in "file", left as an exercise to the reader.

    var filename = save_path + "." + _get_save_extension()
    return ResourceSaver.save(mesh, filename)

To use EditorImportPlugin, register it using the EditorPlugin.add_import_plugin method first.

Tutorials

Methods

Dictionary[]

_get_import_options ( String path, int preset_index ) virtual const

int

_get_import_order ( ) virtual const

String

_get_importer_name ( ) virtual const

bool

_get_option_visibility ( String path, StringName option_name, Dictionary options ) virtual const

int

_get_preset_count ( ) virtual const

String

_get_preset_name ( int preset_index ) virtual const

float

_get_priority ( ) virtual const

PackedStringArray

_get_recognized_extensions ( ) virtual const

String

_get_resource_type ( ) virtual const

String

_get_save_extension ( ) virtual const

String

_get_visible_name ( ) virtual const

Error

_import ( String source_file, String save_path, Dictionary options, String[] platform_variants, String[] gen_files ) virtual const

Error

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


Method Descriptions

Dictionary[] _get_import_options ( String path, int preset_index ) virtual const

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