Search code examples
godotgodot4godot3

Can I trigger "(Re)Import Assets" from plugin code in Godot?


I am writing a plugin for custom import assets from OS. I pick assets on disk and copy them to Godot project structure. Then I need to trigger generating .import file for the imported images, but I cannot see any way to do it from code.

I know there is a way of writing own import plugin and import assets from Godot IDE but I prefer to do the task by standalone separated plugin.

Found EditorImportPlugin class but it does not do what I am looking for.


Solution

  • There are methods in the EditorFileSystem class for managing file imports. You can use update_file, reimport_files, or scan. (snake_case names are GDScript, the C# equivalents are UpdateFile, ReimportFiles, and Scan)

    The documentation for reimport_files notes:

    Reimports a set of files. Call this if these files or their .import files were directly edited by script or an external program.

    If the file type changed or the file was newly created, use update_file or scan.

    A small example of how to get and use the EditorFileSystem instance from an EditorScript (C#):

    var filesystem = GetEditorInterface().GetResourceFilesystem();
    filesystem.Scan()