Godot Version
v4.3.stable.official [77dcf97d8]
Question
I have a number of .tres files that are of a certain resource type all in a specific folder. I want to be able to pick one of these files randomly to read from. Options like DirAccess
provide access to directory folders and I can easily get a random file when running from the Editor, but on export, all file names are changed to .remap or .import.
I would like to avoid hardcoding something like searching for the .remap
or .import
string at the ends of files, etc. I would also like to avoid disabling the project/import settings that create this remapping.
Is there a method for loading these files in a way similar to DirAccess.get_files_at()
that won’t break on project export? My best idea right now is to preload them manually to an Array in a singleton, like in the example below.
const BASE_UPGRADE_POOL : Array[TowerUpgrade] = [
preload("res://tower_upgrades/coin_respawn.tres"),
preload("res://tower_upgrades/damage_upgrade.tres"),
preload("res://tower_upgrades/gem_oven.tres"),
...
]
I understand that ResourceLoader seems to be getting a neat upgrade in 4.4 which will resolve this, I’m just wondering how others have approached this in the past.