ProjectSettings.LoadResourcePack and DirAccess

Godot Version 4.2.2

I’ve noticed that when I use ProjectSettings.LoadResourcePack to load .pck files I only get .import files when using DirAccess.GetFilesAt() or DirAccess.GetNext() to find files. In this case I was looking for .ogg files.

My workaround was to simply remove the .import from the file name to get the right file and it seems to work since I can play the music loaded from the .pck files. But this feels “wrong”. Is there a better way to scan for files?

For context: I do not know before hand what music tracks my game will include since DLC can add more. So I scan the res://sound/music/ folder for “albums”, each including a few “ogg” music files.

I think you’ll have to make use of DirAcess.get_next()

Check if the example script prints more than .gd and .imports

func dir_contents(path):
    var dir =
    if dir:
        var file_name = dir.get_next()
        while file_name != "":
            if dir.current_is_dir():
                print("Found directory: " + file_name)
                print("Found file: " + file_name)
            file_name = dir.get_next()
        print("An error occurred when trying to access the path.")


1 Like

I do use GetNext and get expected results in editor runs. The problem is when I load in extenal packages, think DLC and MODs. Thus the mention of ProjectSettings.LoadResourcePack.

Thanks, I’ll have a look.

[Edit] I see now it is not only manually loaded .pck but also the game export build itself that cause same thing. I’ve tested with manually loaded pck from start so did not even notice this until reading that issue and testing it myself. Well, at least I have a working workaround.