Table of Contents

Class EditorImportPlugin

Namespace
Godot
Assembly
GodotSharpEditor.dll

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 _GetRecognizedExtensions() and _GetResourceType(). 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":

using Godot;

public partial class MySpecialPlugin : EditorImportPlugin { public override string _GetImporterName() { return "my.special.plugin"; }

  public override string _GetVisibleName()
  {
      return "Special Mesh";
  }

  public override string[] _GetRecognizedExtensions()
  {
      return new string[] { "special", "spec" };
  }

  public override string _GetSaveExtension()
  {
      return "mesh";
  }

  public override string _GetResourceType()
  {
      return "Mesh";
  }

  public override int _GetPresetCount()
  {
      return 1;
  }

  public override string _GetPresetName(int presetIndex)
  {
      return "Default";
  }

  public override Godot.Collections.Array<Godot.Collections.Dictionary> _GetImportOptions(string path, int presetIndex)
  {
      return new Godot.Collections.Array<Godot.Collections.Dictionary>
      {
          new Godot.Collections.Dictionary
          {
              { "name", "myOption" },
              { "default_value", false },
          }
      };
  }

  public override int _Import(string sourceFile, string savePath, Godot.Collections.Dictionary options, Godot.Collections.Array<string> platformVariants, Godot.Collections.Array<string> genFiles)
  {
      using var file = FileAccess.Open(sourceFile, FileAccess.ModeFlags.Read);
      if (file.GetError() != Error.Ok)
      {
          return (int)Error.Failed;
      }

      var mesh = new ArrayMesh();
      // Fill the Mesh with data read in "file", left as an exercise to the reader.
      string filename = $"{savePath}.{_GetSaveExtension()}";
      return (int)ResourceSaver.Save(mesh, filename);
  }

}

To use EditorImportPlugin, register it using the AddImportPlugin(EditorImportPlugin, bool) method first.

public class EditorImportPlugin : ResourceImporter, IDisposable
Inheritance
EditorImportPlugin
Implements
Inherited Members

Constructors

EditorImportPlugin()

public EditorImportPlugin()

Methods

AppendImportExternalResource(string, Dictionary, string, Variant)

This function can only be called during the _Import(string, string, Dictionary, Array<string>, Array<string>) 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 the customOptions. Additionally, in cases where multiple importers can handle a file, the customImporter ca be specified to force a specific one. This function performs a resource import and returns immediately with a success or error code. generatorParameters defines optional extra metadata which will be stored as generator_parameters in the remap section of the .import file, for example to store a md5 hash of the source data.

public Error AppendImportExternalResource(string path, Dictionary customOptions = null, string customImporter = "", Variant generatorParameters = default)

Parameters

path string
customOptions Dictionary
customImporter string
generatorParameters Variant

Returns

Error

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

_GetImportOptions(string, int)

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

public virtual Array<Dictionary> _GetImportOptions(string path, int presetIndex)

Parameters

path string
presetIndex int

Returns

Array<Dictionary>

_GetImportOrder()

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 ResourceImporter.ImportOrder for some predefined values.

public virtual int _GetImportOrder()

Returns

int

_GetImporterName()

Gets the unique name of the importer.

public virtual string _GetImporterName()

Returns

string

_GetOptionVisibility(string, StringName, Dictionary)

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. For example:

public void _GetOptionVisibility(string option, Godot.Collections.Dictionary options)
  {
      // Only show the lossy quality setting if the compression mode is set to "Lossy".
      if (option == "compress/lossy_quality" && options.ContainsKey("compress/mode"))
      {
          return (int)options["compress/mode"] == CompressLossy; // This is a constant you set
      }
  return true;

}

Returns true to make all options always visible.

public virtual bool _GetOptionVisibility(string path, StringName optionName, Dictionary options)

Parameters

path string
optionName StringName
options Dictionary

Returns

bool

_GetPresetCount()

Gets the number of initial presets defined by the plugin. Use _GetImportOptions(string, int) to get the default options for the preset and _GetPresetName(int) to get the name of the preset.

public virtual int _GetPresetCount()

Returns

int

_GetPresetName(int)

Gets the name of the options preset at this index.

public virtual string _GetPresetName(int presetIndex)

Parameters

presetIndex int

Returns

string

_GetPriority()

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

public virtual float _GetPriority()

Returns

float

_GetRecognizedExtensions()

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

public virtual string[] _GetRecognizedExtensions()

Returns

string[]

_GetResourceType()

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

public virtual string _GetResourceType()

Returns

string

_GetSaveExtension()

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

public virtual string _GetSaveExtension()

Returns

string

_GetVisibleName()

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

public virtual string _GetVisibleName()

Returns

string

_Import(string, string, Dictionary, Array<string>, Array<string>)

Imports sourceFile into savePath with the import options specified. The platformVariants and genFiles 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.

public virtual Error _Import(string sourceFile, string savePath, Dictionary options, Array<string> platformVariants, Array<string> genFiles)

Parameters

sourceFile string
savePath string
options Dictionary
platformVariants Array<string>
genFiles Array<string>

Returns

Error