Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Problem of downloading Unity Asset Bundle in WebGL

Discussion in 'Scripting' started by Lim-Leong-Kee, Mar 15, 2017.

  1. Lim-Leong-Kee

    Lim-Leong-Kee

    Joined:
    Mar 29, 2014
    Posts:
    4
    Hi all. Does anyone experience the problem of downloading Unity Asset Bundle in WebGL?

    I use the following code to build an Asset Bundle file for WebGL.

    [MenuItem ("Assets/Build AssetBundles/WebGL")]
    static void BuildAllAssetBundlesWebGL()
    {
    BuildPipeline.BuildAssetBundles( "Assets/AssetBundles", BuildAssetBundleOptions.None, BuildTarget.WebGL );
    }

    Then I upload the Asset Bundle file to a Server.

    In Unity, I use WWW.LoadFromCacheOrDownload() to load the Asset Bundle for WebGL. And I use www.assetBundle to get the Asset Bundle.

    When I run the Unity WebGL in a browser, it fails to download the Asset Bundle file and show the following error:
    You are trying to load data from a www stream which had the following error when downloading. Unknown error.

    I am able to download the Asset Bundle in Unity Editor and Android platform, but somehow it just cannot download in WebGL.

    The Unity version I am using is 5.5.0f3.
    Please help. Thanks.
     
    Last edited: Mar 15, 2017
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
    I have not experienced any issues myself as long as the address is correct. If you are set to webgl in editor and it is downloading correctly, then you probably have the links correct. It's possible where you are hosting your game perhaps is creating an issue? We have a webgl game on facebook and it hasn't given us trouble yet.

    Sadly, Unknown error doesn't say much. If you run the developer console in your browser, do you happen to get any additional info?
     
  3. Lim-Leong-Kee

    Lim-Leong-Kee

    Joined:
    Mar 29, 2014
    Posts:
    4
    Problem solved. After I build for WebGL and get the build files (index.html, Release folder, TemplateData folder), I upload all the build files to the Server, then open the index.html from the Server and now I am able to download the Asset Bundle for WebGL and successfully show the content inside the Asset Bundle in a browser. Thanks. :)
     
  4. Rbhaniwal

    Rbhaniwal

    Joined:
    Jan 23, 2015
    Posts:
    33
    hello @Brathnann @Lim-Leong-Kee

    Facing same issue but no luck with this solution. Any other solution ??

    Thanks.
     
  5. Rbhaniwal

    Rbhaniwal

    Joined:
    Jan 23, 2015
    Posts:
    33
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
    There are two easy ways to try to find out what is going wrong.

    Put log viewer in the project. https://www.assetstore.unity3d.com/en/#!/content/12047
    This is an easy to use asset that is free. It adds an option in the editor window for Reporter which creates a prefab that you add to your starting scene. Once your game loads, you can do a swirling motion to bring up the console overlay.

    The other method is try the developer console in your browser.
    On firefox and chrome, F12 should bring it up. But if it doesn't, you'll need to find the option in the menu.

    There are other ways, but these two will show you stuff that might print out in the Unity console, which can include null errors, print/debug.log statements, and many other things.
     
  7. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    869
    The actual URL to the asset on the server will be different when you run it in the editor vs running it in a browser on your site. The first part of the URL will be different.
     
  8. kartoonist435

    kartoonist435

    Joined:
    Feb 14, 2015
    Posts:
    71
    Can you clarify? What is the URL of the asset on a server vs editor? I am having this issue downloading an Asset bundle to my WebGL project.
     
  9. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
    Such an old post, probably would be better to start your own thread if you are having issues.

    If you are hosting your assetbundle separate from your project (like on a cdn) the path isn't any different.

    If you are hosting it in streamingassets, then you should be using application.streamingAssetsPath, which while the path is different technically, by using that shortcut, Unity will point to the correct location.
     
  10. kartoonist435

    kartoonist435

    Joined:
    Feb 14, 2015
    Posts:
    71
  11. FarhanHakim

    FarhanHakim

    Joined:
    Jan 31, 2020
    Posts:
    1