I am finally at the stage where I am trying to export a build, yay! Right now I have code that searches within my res//:art/face_bits folder for custom resources and adds them to arrays by type. It works beautifully in the editor, but doesn’t populate the arrays in my export build.
here’s the code:
func _ready():
populate_face_bit_arrays()
func get_all_files_from_directory(path : String, file_ext:= "", files := []):
var dir = DirAccess.open(path)
if dir:
dir.list_dir_begin()
var file_name = dir.get_next()
while file_name != "":
if dir.current_is_dir():
files = get_all_files_from_directory(dir.get_current_dir()+"/"+file_name,file_ext,files)
else:
if file_ext && file_name.get_extension() != file_ext:
file_name = dir.get_next()
continue
files.append(dir.get_current_dir()+"/"+file_name)
file_name = dir.get_next()
dir.list_dir_end()
return files
func populate_face_bit_arrays():
var files = get_all_files_from_directory("res://art/face_bits", "tres")
for file in files:
var resource = load(file)
if resource is FaceShape:
face_shapes.append(resource)
elif resource is FaceEars:
face_ears.append(resource)
research has pointed me toward the Resources>filters to export non-resource files/folders… but I’m having trouble finding documentation about what to enter into that field to get the results I want.
Because Godot rename/remap the files after export so the files you’ll find will be different from what you want, you need to use ResourceLoader.list_directory() to get the original files paths (Godot 4.4 dev 5 or higher is required)
I’m not sure what you mean. I know I could totally create some sort of master index that hard codes my resource arrays, but that’s something I then have to maintain.
I want to make a custom resource, put it in the appropriate folder, and have it just work… and then just take it out of that folder when I decide i don’t want it in the game. This is 100% possible in the editor, I don’t get why it wouldn’t be just as easy in a build?
func get_all_files_from_directory(path : String, file_ext:= "", files := []):
var resources = ResourceLoader.list_directory(path)
for res in resources:
print(str(path+res))
if res.ends_with("/"):
get_all_files_from_directory(path+res, file_ext, files)
elif file_ext && res.ends_with(file_ext):
files.append(path+res)
return files
BUT. Something about the upgrade to 4.4 broke all my button and tab signals. I hacked it back into functionality by connecting all the signals via script rather than through the editor. I’m close enough to the end of this project that I don’t mind duct taping that, but I’ll have to find a better solution for next time… two steps forward, one step back!