Godot Version
4.5
Question
I have a lot of similar resource files that I want to load in an Array of Resource at startup.
Reading the forum or reddit, I came to this weird solution (removing “remap” extensions on “tres” files…):
var _resources: Array[Resource]
var _dir := DirAccess.open("res://resources/enemies/")
for _file: String in _dir.get_files():
print(_file)
if (_file.get_extension() == "remap"):
_file = _file.replace(".remap", "")
if (_file.get_extension() == "tres"):
var _resource := ResourceLoader.load(_dir.get_current_dir() + "/" + _file)
_resources.push_back(_resource)
But I wonder if this is the right way to do it, because it smells like a poor workaround…
There should be a better solution when you have an undefined number of resources, or no ?
In my case, I have resources describing enemies, and I want to be able to pick up at random in this list of enemies, that could grow as soon as I invent new ones…