This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I have a project which works fine when running from the editor, but exporting to release on Linux results problems. Whenever a sound effect would play, the game will crash. I thought there may be missing files, I exported with all issues, and the problem remains.

Note the game works perfectly fine running from the editor, what could be the issue?

in Engine by (276 points)

What does the code for playing the sound effect look like?

Essentially, I have a singleton which loads all the sound effects at runtime, and assigns them to a constant in a dictionary to be accessed, so like:

###Audio singleton
enum {EXAMPLE}
Sounds = {EXAMPLE : "pathtofile"}

_ready():
    Sounds[EXAMPLE] = load(Sounds[EXAMPLE])

func play(sound=EXAMPLE):
    player = AudioStreamPlayer.new()
    ###set bus and stream
    stream = Sounds[sound]
    player.play()

This is very simplified. In reality I have a directory with multiple sound effects, so each constant corresponds to an array containing like hit1, hit2 and hit3. When the function is called, one will play.

When I run from terminal I get invalid index 0 on array errors. To me that says the files aren't being found or aren't loading into the array for whatever reason. The thing that confuses me is that it works perfectly fine in the editor, so it's something to do with how it's exporting.

Are the paths constant strings or are you using a Directory to find them? Because imported files are not at their original location upon export, they're in the import folder.

Ah, I think that might be the source of the issue. The paths are strings to directories which contain the files. Basically when I want to add a bunch of player gets hurt sounds to the game, I make a PLAYER_HURT constant, put it in a dictionary, and assign it to an array of the contents of res://assets/sounds/player/hurt/, for example.

This allows me to call Audio.play(Audio.PLAYER_HURT) from elsewhere, without it always being the same sound, so slightly variable sounds or multiple sound effects for the same event. The singleton randomly picks one from the array.

How do I work around this issue? By just loading every file by hand in the script? Is there a less cumbersome way of accomplishing what I want to do?

1 Answer

0 votes
Best answer

When exporting the project, the imported files can no longer be found in their original locations and are instead stored in the .import folder. However, the .import files are still in their original locations. To use Directory to look through a folder in order to find files, you need to look for the .import files instead. Then, remove the .import from the file name, and load the resulting path (the ResourceLoader will automatically account for the moved file).

by (8,580 points)
selected by

Great! Does this also apply to things like .tscn files? Is there a list of things that should be obtained from a .import file rather than the file itself if it's taken from a directory?

It doesn't apply to tscn files, just anything that has an import file appear next to it and has an imported version of it in the .import folder.

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.