Search Unity

Resolved WebGL Build hosted in subfolder - Addressables Failing to Load!

Discussion in 'Web' started by Sagan_CottenhamB, Jan 29, 2024.

  1. Sagan_CottenhamB

    Sagan_CottenhamB

    Joined:
    Mar 23, 2022
    Posts:
    5
    Hi all! I've had a published WebGL build hosted in a subfolder of our website and working flawlessly for a long time. During that time, we only used the StreamingAssets folder for one BuildProperties file, and it was just a version / BuildGUID text file used by the hosting website.

    My project structure looks something like this:
    upload_2024-1-29_16-4-40.png

    The Unity build lives in the /App folder, here:
    upload_2024-1-29_16-5-26.png

    When we decided to start using Addressables, the "aa" folder also became part of the StreamingAssets folder. This is where we began running into problems: If my build is located in a subfolder, like "App", the Addressables system isn't able to retrieve the catalog.bin or any other StreamingAssets files.

    To give a better idea of what's happening, the catalog.bin lives at:
    https://MyWebSite.com/App/StreamingAssets/aa/catalog.bin

    But the Addressables system looks for it at:
    https://MyWebSite.com/StreamingAssets/aa/catalog.bin

    After investigating further, it looks like Unity always expects the build to exist at the root of any website, as the
    Application.streamingAssetsPath property always returns "MyWebSite.com/StreamingAssets" at runtime, regardless of where the build is located.

    Basically, Unity appears to be using Absolute pathing to get the StreamingAssets folder, rather than Relative pathing to say "get my sibling folder, the StreamingAssets folder"

    Which brings me to my final question: Is there some way to have the Application paths adjust to where the build is going to be located, even if it has to be defined at compile-time?
     

    Attached Files:

  2. Sagan_CottenhamB

    Sagan_CottenhamB

    Joined:
    Mar 23, 2022
    Posts:
    5
    Update: If I place just the StreamingAssets folder in the project's root and leave the rest of the build in the App folder, it will find the aa folder no problem, because the absolute path will line up again. I'd like to avoid doing this, though, because it muddies our folder structure and would likely be an easily forgotten step when we update the build.
     
  3. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,771
    Have you tried editing the index.html

    Heres a kinda default one

    Code (JavaScript):
    1.       var buildUrl = "Build";
    2.       var loaderUrl = buildUrl + "/Web.loader.js";
    3.       var config = {
    4.         arguments: [],
    5.         dataUrl: buildUrl + "/Web.data.gz",
    6.         frameworkUrl: buildUrl + "/Web.framework.js.gz",
    7.         codeUrl: buildUrl + "/Web.wasm.gz",
    8.         streamingAssetsUrl: "StreamingAssets",
    9.         companyName: "DefaultCompany",
    10.         productName: "My project",
    11.         productVersion: "0.1",
    12.         showBanner: unityShowBanner,
    13.       };
    surely if you put in app/StreamingAssets it works yes? or even buildUrl+...
     
  4. Sagan_CottenhamB

    Sagan_CottenhamB

    Joined:
    Mar 23, 2022
    Posts:
    5
    Thanks for the quick reply! That certainly sounds like what I'm looking for. Unfortunately, I won't be able to test this until tomorrow morning, but I'll let you know as soon as I'm able to check it out.
     
  5. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,771
    I make no promises, but logic says it should matter
     
  6. Sagan_CottenhamB

    Sagan_CottenhamB

    Joined:
    Mar 23, 2022
    Posts:
    5
    That worked, thank you very much!
     
  7. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,771
    sweeet - which one btw? one thing you can do of course is edit the whole base template so it always includes the build url etc, or whatever.. maybe even submit it as a bug as a bug in the template because as you say its expecting /StreamingAssets
     
  8. Sagan_CottenhamB

    Sagan_CottenhamB

    Joined:
    Mar 23, 2022
    Posts:
    5
    We handle creating the UnityInstance slightly differently than the default html template, but still pass in the same config object, so I hard-coded the "streamingAssetsUrl" to "App/StreamingAssets". Since there was no leading or trailing slash, I kept the same pattern. Seems to work like a charm!

    I agree this could be considered a bug, or, at the very least, should be better documented. I must've searched the documentation and forums for hours without any luck before finally creating this thread.
     
    bugfinders likes this.