Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Any way to browse StreamingAssets folder in WebGL project?

Discussion in 'Web' started by Sharlatan, Oct 4, 2017.

  1. Sharlatan

    Sharlatan

    Joined:
    Jul 23, 2013
    Posts:
    111
    Hello everyone,

    is it possible to somehow browse the StreamingAssets folder if you have a WebGL project?

    I know that I can access specific files in my StreaminAssets folder with UnityWebRequest object, which is described here: https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html

    But I'd like to be able to browse the existing folders within StreamingAssets. I'm working on a game supporting mods and part of that includes, that users can add content to StreamingAssets and it's subfolders.
    This means that I need some functionality to browse StreamingAssets to see, what files and (sub)folders are present.

    On "normal" platforms, I just do something like this:

    Code (CSharp):
    1. var filePaths = Directory.GetFiles(Application.streamingAssetsPath, "*", SearchOption.AllDirectories);
    2.      
    3. foreach (var filePath in filePaths)
    4. {
    5.   //do stuff with files
    6. }
    But obviously, that doesn't work in a WebGL project/with a UnityWebRequest object.
    A solution wouldn't necessarily have to be as comfortable as Directory.GetFile(...). I'd be more than happy with using some recursion or whatever. But even for that I would at least need to be able to somehow read the contents of a folder.

    Does anyone have any idea if there's a solution to this?

    Thank you very much!
     
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    what about having some kind of manifest file that tells you what's in that folder?
     
  3. Sharlatan

    Sharlatan

    Joined:
    Jul 23, 2013
    Posts:
    111
    Thank you very much for your input! A manifest file would certainly work.

    I was just hoping for there to maybe be some Unity functionality I didn't know about that would let me analyze the StreamingAssets folder. But since you're from Unity, I strongly assume, you'd have told me so if that was the case :)

    If anyone else has another idea, that's still very welcome of course!

    If not, I'll have to think about whether it's worth to go the manifest file route or not. Thing is, I'm not targeting WebGL in the end anyway. Having a WebGL build (in my case) is just super convenient to share progress with people that are not directly involved in the project. Just being able to share an URL is a huge plus. No downloading, no extracting, no nothing. Just clicking on a link and you're good to go.
    Using a manifest file would mean that it either has to be written by hand, which isn't feasible at all, or that I'll have to write a tool that auto generates the manifest file. And that tool will have to be maintained and expanded throughout the whole project. It's would be absolutely doable but also sounds like might become more of a hassle than requiring people to download new builds.

    So, please just don't hold it against me if I'm not going down that route in the end ;)
    It's certainly a solution that would work well and I thank you for that. I'm just not sure if it's worth the effort in my case.

    All the best,

    Sharlatan
     
  4. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    If you are not targeting WebGL, then why don't you just use System.IO functions to know what files are there?
     
  5. Sharlatan

    Sharlatan

    Joined:
    Jul 23, 2013
    Posts:
    111
    Sorry, I think my post was a bit confusing. What I was trying to say was this: I'm not targeting WebGL in the end but during development it proved to be very convenient to make a WebGL build and upload it to a server whenever I wanted to share progress and get feedback with/from people.
    And that's why I'd like the project to stay WebGL compatible as long as it's not too much work to do so.
     
  6. Hiverlab

    Hiverlab

    Joined:
    Jul 10, 2015
    Posts:
    5
    Hi if i use the manifest file, doesnt that mean that i will have to know the exact filenames of all the files (maybe 200) beforehand?
     
  7. witchthewicked222

    witchthewicked222

    Joined:
    Jun 14, 2020
    Posts:
    3