Godot Version
4.6.2stable
What I’m trying to do
I have a character selection screen that generates buttons for each playable character. Originally, I manually maintained a dictionary like this:
gdscript
var characters = {
"warrior": preload("res://characters/warrior.tscn"),
"mage": preload("res://characters/mage.tscn")
}
Then I iterated over the dictionary to create the buttons. That worked fine both in the editor and in the exported build.
Now I want to automate the process by scanning a folder (res://scenes/characters/) and filling the dictionary at runtime. My code looks roughly like this:
gdscript
func set_char_dic():
characters.clear()
var dir = DirAccess.open("res://scenes/characters/")
if dir:
dir.list_dir_begin()
var file_name = dir.get_next()
while file_name != "":
if file_n
ame.ends_with(".tscn"):
var path = "res://scenes/characters/" + file_name
var scene = load(path)
characters[file_name.get_basename()] = scene
file_name = dir.get_next()
dir.list_dir_end()
This works flawlessly in the editor. I can see all the characters in the dictionary, and the buttons appear correctly.
The problem
When I export the project (Windows, with embedded PCK), the characters dictionary is completely empty. I added a print(characters) right after scanning, and it outputs {}. No errors, no crashes – just an empty dictionary.
What I’ve checked
-
The
.tscnfiles are definitely inside thecharactersfolder. -
In the export preset, I tried adding
res://scenes/characters/*to the “Filters to export non‑resource files/folders”, but that didn’t help (and I understand.tscnfiles are resources, not non-resources). -
I also tried setting the export mode to “Export all resources” – same empty dictionary.
-
Using
ResourcePreloaderworks, but I’d rather not manually list every character.
My suspicion
It seems like DirAccess can’t properly iterate over the res:// path after exporting, even though the files are inside the PCK. Is that expected? I thought Godot 4 supported virtual file system access in exported builds via DirAccess.
Is there a reliable way to dynamically discover and load scene files from a folder in an exported game? Or do I need to resort to a static preload array or a ResourcePreloader node?
Any help would be greatly appreciated!

