0 votes

I'm trying to go through every .wav file in my game's audio folder and turn that into an AudioStreamPlayer.
So I tried to do this with the help of the sample code in the documentation for the Directory class. The documentation also warns you that the source asset of most resources won't be included in the exported version of the game and to "use ResourceLoader to access imported resources," and I assumed that meant I could just do ResourceLoader.load() instead of load() so here's the code:

var directory = Directory.new()

if directory.open("res://assets/audio/") != OK:
    return

directory.list_dir_begin(true)
var file = directory.get_next()
while file != "":
    if file.get_extension() == "wav":
        var sound = AudioStreamPlayer.new()
        add_child(sound)
        sound.name = file.get_slice(".", 0)
        sound.stream = ResourceLoader.load(directory.get_current_dir() + file)

    file = directory.get_next()

This works fine when testing in editor except, like the documentation warned, the audio doesn't get loaded in on an exported version of the game. And I can't find anything in the documentation that tells me how to load the "imported" versions of the resources. So... how can I get the imported versions of resources rather than their "source assets?" The only thing I found on Google just appears to be a bandage solution.

Godot version Godot 3.5.1.stable
in Engine by (37 points)

1 Answer

0 votes
Best answer

Okay so, it seems like while the source files themselves are missing from the directory upon export, you can still reference them with load()... absolutely confused on why it works like this.

The solution was to edit the code to look for .import files instead of .wav, and then when you get to the load function, remove the .import portion of the filename so it's referencing that wav file rather than its import file. (and I also had to add a file separator inbetween the directory and the file)

directory.get_current_dir() + "/" + file.get_file().replace(".import", "")
by (37 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.