Skip to main content

IEditorImportPlugin

Trait IEditorImportPlugin 

pub trait IEditorImportPlugin: GodotClass<Base = EditorImportPlugin> + You_forgot_the_attribute__godot_api {
Show 23 methods // Required methods fn get_importer_name(&self) -> GString; fn get_visible_name(&self) -> GString; fn get_preset_name(&self, preset_index: i32) -> GString; fn get_recognized_extensions(&self) -> PackedArray<GString>; fn get_import_options( &self, path: GString, preset_index: i32, ) -> Array<AnyDictionary>; fn get_save_extension(&self) -> GString; fn get_resource_type(&self) -> GString; fn import( &mut self, source_file: GString, save_path: GString, options: Dictionary<Variant, Variant>, platform_variants: Array<GString>, gen_files: Array<GString>, ) -> Error; // Provided methods fn init(base: Base<Self::Base>) -> Self { ... } fn on_notification(&mut self, what: ObjectNotification) { ... } fn on_get(&self, property: StringName) -> Option<Variant> { ... } fn on_set(&mut self, property: StringName, value: Variant) -> bool { ... } fn on_validate_property(&self, property: &mut PropertyInfo) { ... } fn on_get_property_list(&mut self) -> Vec<PropertyInfo> { ... } fn on_property_get_revert(&self, property: StringName) -> Option<Variant> { ... } fn to_string(&self) -> GString { ... } fn get_preset_count(&self) -> i32 { ... } fn get_priority(&self) -> f32 { ... } fn get_import_order(&self) -> i32 { ... } fn get_format_version(&self) -> i32 { ... } fn get_option_visibility( &self, path: GString, option_name: StringName, options: Dictionary<Variant, Variant>, ) -> bool { ... } fn can_import_threaded(&self) -> bool { ... } fn get_build_dependencies(&self, path: GString) -> PackedArray<GString> { ... }
}
Expand description

§Interface trait for class EditorImportPlugin.

Functions in this trait represent constructors (init) or virtual method callbacks invoked by the engine.

Base interfaces: IResourceImporter > IRefCounted > IObject.
(Strike-through means some intermediate Godot classes are marked final, and can thus not be inherited by GDExtension.)

See also Godot docs for EditorImportPlugin methods.

Required Methods§

fn get_importer_name(&self) -> GString

Gets the unique name of the importer.

fn get_visible_name(&self) -> GString

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

fn get_preset_name(&self, preset_index: i32) -> GString

Gets the name of the options preset at this index.

fn get_recognized_extensions(&self) -> PackedArray<GString>

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

fn get_import_options( &self, path: GString, preset_index: i32, ) -> Array<AnyDictionary>

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

fn get_save_extension(&self) -> GString

Gets the extension used to save this resource in the .godot/imported directory (see [member ProjectSettings.application/config/use_hidden_project_data_directory]).

fn get_resource_type(&self) -> GString

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

fn import( &mut self, source_file: GString, save_path: GString, options: Dictionary<Variant, Variant>, platform_variants: Array<GString>, gen_files: Array<GString>, ) -> Error

Imports source_file with the import options specified. Should return @GlobalScope.OK if the import is successful, other values indicate failure.

The imported resource is expected to be saved to save_path + "." + _get_save_extension(). If a different variant is preferred for a feature tag, save the variant to save_path + "." + tag + "." + _get_save_extension() and add the feature tag to platform_variants.

If additional resource files are generated in the resource filesystem (res://), add their full path to gen_files so that the editor knows they depend on source_file.

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

Provided Methods§

fn init(base: Base<Self::Base>) -> Self

Godot constructor, accepting an injected base object.

base refers to the base instance of the class, which can either be stored in a Base<T> field or discarded. This method returns a fully-constructed instance, which will then be moved into a Gd<T> pointer.

If the class has a #[class(init)] attribute, this method will be auto-generated and must not be overridden.

fn on_notification(&mut self, what: ObjectNotification)

Called when the object receives a Godot notification.

The type of notification can be identified through what. The enum is designed to hold all possible NOTIFICATION_* constants that the current class can handle. However, this is not validated in Godot, so an enum variant Unknown exists to represent integers out of known constants (mistakes or future additions).

This method is named _notification in Godot, but on_notification in Rust. To send notifications, use the Object::notify method.

See also in Godot docs:

fn on_get(&self, property: StringName) -> Option<Variant>

Called whenever get() is called or Godot gets the value of a property.

Should return the given property’s value as Some(value), or None if the property should be handled normally.

See also in Godot docs:

fn on_set(&mut self, property: StringName, value: Variant) -> bool

Called whenever Godot set() is called or Godot sets the value of a property.

Should set property to the given value and return true, or return false to indicate the property should be handled normally.

See also in Godot docs:

fn on_validate_property(&self, property: &mut PropertyInfo)

Called whenever Godot retrieves value of property. Allows to customize existing properties. Every property info goes through this method, except properties added with on_get_property_list().

Exposed property here is a shared mutable reference obtained (and returned to) from Godot.

See also in the Godot docs:

fn on_get_property_list(&mut self) -> Vec<PropertyInfo>

Available on since_api=4.3 only.

Called whenever Godot get_property_list() is called, the returned vector here is appended to the existing list of properties.

This should mainly be used for advanced purposes, such as dynamically updating the property list in the editor.

See also in Godot docs:

fn on_property_get_revert(&self, property: StringName) -> Option<Variant>

Called by Godot to tell if a property has a custom revert or not.

Return None for no custom revert, and return Some(value) to specify the custom revert.

This is a combination of Godot’s Object::_property_get_revert and Object::_property_can_revert. This means that this function will usually be called twice by Godot to find the revert.

Note that this should be a pure function. That is, it should always return the same value for a property as long as self remains unchanged. Otherwise, this may lead to unexpected (safe) behavior.

fn to_string(&self) -> GString

String representation of the Godot instance.

Override this method to define how the instance is represented as a string. Used by impl Display for Gd<T>, as well as str() and print() in GDScript.

fn get_preset_count(&self) -> i32

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.

By default, there are no presets.

fn get_priority(&self) -> f32

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

fn get_import_order(&self) -> i32

Gets the order of this importer to be run when importing resources. Importers with lower 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 0 unless overridden by a specific importer. See [enum ResourceImporter.ImportOrder] for some predefined values.

fn get_format_version(&self) -> i32

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

fn get_option_visibility( &self, path: GString, option_name: StringName, options: Dictionary<Variant, Variant>, ) -> bool

Gets whether the import option specified by option_name should be visible in the Import dock. The default implementation always returns true, making all options visible. This is mainly useful for hiding options that depend on others if one of them is disabled.

func _get_option_visibility(path, option_name, options):
	# Only show the lossy quality setting if the compression mode is set to "Lossy".
	if option_name == "compress/lossy_quality" and options.has("compress/mode"):
		return int(options["compress/mode"]) == COMPRESS_LOSSY # This is a constant that you set

	return true

fn can_import_threaded(&self) -> bool

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 importer’s implementation is thread-safe and can be run in parallel, override this with true to optimize for concurrency.

If not overridden, returns false.

fn get_build_dependencies(&self, path: GString) -> PackedArray<GString>

Called when the engine compilation profile editor wants to check what build options an imported resource needs. For example, ResourceImporterDynamicFont has a property called [member ResourceImporterDynamicFont.multichannel_signed_distance_field], that depends on the engine to be build with the “msdfgen” module. If that resource happened to be a custom one, it would be handled like this:

func _get_build_dependencies(path):
	var resource = load(path)
	var dependencies = PackedStringArray()

	if resource.multichannel_signed_distance_field:
		dependencies.push_back("module_msdfgen_enabled")

	return dependencies

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§