Loading files from user://

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mymokol

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?

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.

timothybrentwood | 2021-11-04 13:43

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.

mymokol | 2021-11-04 13:49

:bust_in_silhouette: Reply From: timothybrentwood

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:

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