StreamingAssets access in WebGL?

Hello!

I’m trying to get a build of our game up and running in WebGL, and while I got the game itself running, I can’t seem to figure out how to properly access the StreamingAssets folder in the WebGL build. We store images and text files in there that we need to access (importing them into the Unity project won’t work, long story on the reason).

Here’s the code we’re trying to use:

path = Application.streamingAssetsPath+"/Level Files/";

            if (path.Contains("://")) {//if we're on the web, we have to wait until the WWW returns the real file path
                WWW www = new WWW(path);
                yield return www;
                path = www.text;
            }
//get the streaming assets directory that holds all of our level files and then get all our files
        DirectoryInfo dir = new DirectoryInfo(path);
       
        //get all of our level files
        info = dir.GetFiles();

www.text does return an HTML file, but when we try to get the directory info, we get the following error (when running locally):

The single slash after http: is not a typo.

Any ideas would be greatly appreciated!

Quick bump to get it back on the first page during normal hours :slight_smile:

DirectoryInfo is meant to get information about folders on your local hard disk and cannot be used to retrieve information about folders or files residing on a remote server.

Got it, certainly makes sense. What would be the proper call(s) to retrieve files from StreamingAssets in a web build then?

I’d create an editor script that looks in your project folder and creates a manifest of all the files located there as a CSV or some other text file. Then use WWW to load the manifest from the server in your build.

That sounds like it could work, but is there really no easier way? It packages up your StreamingAssets folder right alongside the rest of the files at the top folder level…maybe I’ll consult my web developer friends? Just thought Unity would have a way to access them via WebGL builds.

Depending on what is installed on the server I’m sure it could look at the directory and send a response back containing a list of files. At that point you’re beyond the scope of this forum.

It’s not clear to me why the requested functionality isn’t working. Can we add this as a new feature request?

What functionality specifically? You can’t use DirectoryInfo to query a remote folder, that’s not a Unity limitation.