(C#) I have a question in relation to loading list of files from a directory. As I understand it after export files, such as scenes (.tscn), get moved to the .import folder and in its place a metadata file appears (.tscn.remap). If you're using DirAccess to iterate over files in a directory after export then you will get the metadata file instead and ResourceLoader will be unable to load as it had been in the Editor.

The possible solutions to this are:

  1. Trim the .remap suffix from the end of the metadata file when iterating through the directory which due to how the ResourceLoader works will be able to remap it correctly to the original file in .import. This is more due to a quirk in the engine than an intended solution but is very simple to implement.
  2. Manually create a list of all the files in the folder that need to be loaded and load that. This seems to be the "proper" yet cumborsome way to deal with it. I suppose you could create a tool of some kind to auto gather the files for you in a folder but there's an issue; you can't load files dynamically at runtime say if you were loading Mods. (At least as far as I can tell)
  3. Setting Project Settings > Editor > Export > Convert Text Resources To Binary to 'false' but I'm not exactly sure the consequences of disabling that are so for now I'm just avoiding it.

So I'm wondering if anybody knows any other/clean solutions to loading an arbitrary numbers of scenes from a folder at runtime, in my case I'm loading different Enemy Types from a folder called "Enemies".

This seems to be the main issue for this problem: 1

What kind of files do you want to load? Some files (mainly resources) can only be processed by the editor. You should be able to load text files but not images, for example.

    cybereality I'm loading Enemy Scenes from a folder called 'Enemies'. Discussion-wise it can be any kind of resource file I'm more interested in a 'pattern' so to speak for this poarticular use case that I've seen where people put say a collection of <Enemy_Name>.tscn in a folder and load them up using DirAccess or the GDScript alternative.

    tscn files are text files so loading should be possible. The issue is that internally the links to resources (scripts, images, sounds, etc.) are using id numbers that might not map correctly if you are loading dynamically. I have not tried this, but I recall hearing about issues when people attempted to load other resources, like images, so it may have similar rules.

      cybereality That is the case when the 'Convert Text Resources To Binary' is false (which is not the default) in the Project Settings. If that is set to true then as I mentioned the original file that I'm trying to load gets moved to the .import folder leaving in its place a metadata file of <Enemy_Name>.tscn.remap ergo the DirAccess can only find those files.

      What I'm looking for is basically: What is the most efficient way of loading up an array of scenes (or any resource for that matter) from a folder at runtime?

      You may take a look at this pull request of demos, it's about loading packed scenes files at runtime.
      @dannymate: as you may know the folder to load from, even the files names, it would be possible to load your enemies at runtime.

        JusTiCe8 The example is a little out of date so I had to make a couple of changes. It isn't really what I'm looking for unless I'm misunderstanding something. The tscn files get moved to someplace else after export so DirAccess is incapable of finding those files.

        I'm not looking for help for a particular use case, using DirAccess at runtime to load files is apparently not expected behaviour and I'd like to know what exactly others are doing to load an array of files without having to manually enter each and every file path.

        The dirPath is "res://Enemies"