0 votes

I tried asking a similar question earlier, but it was poorly stated and asked something a bit different, so here i am with the correct question now.

I'm trying to load a file from the user:// directory by calling load("user://music/file.wav") (where "file.wav" is the file i'm trying to load, located in the user:// directory). However, it doesn't load at all, unlike what it does when i try exactly the same thing in the res:// directory.

When i print the stream property of the AudioStreamPlayer to which i'm loading the file, it prints [object:null]. Why is the load() function not working outside of res://? is there something i should know about it? And how to resolve this problem?

Godot version 3.2.3
in Engine by (91 points)

You left out an important bit about this being a web app. I think that's what's causing you to not be able to load from user://. When you use Godot on web res:// points internally (I can't remember exactly how this works). Since browsers by default aren't allowed to manipulate filesystems (due to security concerns), I believe user:// points to a cookie, not the local filesystem, on web.

I think this is what's causing your issue. To test this export your game for desktop and test if it works. If it does work, the explanation I gave above is likely the cause of your issues and I don't know how to give you a fix for web. If it doesn't work, you probably have some kind of filesystems permissions issue that you have to resolve before it works.

That's not the case at all, since this is not a web app. I left it out for a reason, the reason being it's not on the web. I had no reason to export it since the thing doesn't work, bugfixing comes before exporting. It doesn't load the file when i press f5 in godot.

1 Answer

+1 vote
Best answer

I looked into this and this has to do with the difference between what a Resource is and what an external file is. This thread does a better job of explaining it than what I can do here:

https://github.com/godotengine/godot-docs/issues/2148

If you want to import a .wav file specifically you'll probably want to use the code from this library:

https://github.com/Gianclgar/GDScriptAudioImport/blob/master/GDScriptAudioImport.gd

by (3,870 points)
selected by
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.