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 Loading Asset Bundles via web

Discussion in 'Scripting' started by tattyswad, Jun 17, 2015.

  1. tattyswad

    tattyswad

    Joined:
    Sep 22, 2010
    Posts:
    106
    Hello,

    I have a scene that I need to get working via the webplayer but it's too big to load in one go so I though I would chop it into bits and load via asset bundles. I can get the bundles to load when they are stored locally but as soon as I export and load to the web the assets don't load. I'm using the same code and I can't figure out what's happening!

    The code I am using is as follows:

    Code (CSharp):
    1.  
    2. using System;
    3. using UnityEngine;
    4. using System.Collections; class NonCachingLoadExample : MonoBehaviour {
    5.     public string BundleURL;
    6.     public string AssetName;
    7.     IEnumerator Start() {
    8.         // Download the file from the URL. It will not be saved in the Cache
    9.         using (WWW www = new WWW(BundleURL)) {
    10.             yield return www;
    11.             if (www.error != null)
    12.                 throw new Exception("WWW download had an error:" + www.error);
    13.             AssetBundle bundle = www.assetBundle;
    14.             if (AssetName == "")
    15.                 Instantiate(bundle.mainAsset);
    16.             else
    17.                 Instantiate(bundle.LoadAsset(AssetName));
    18.             // Unload the AssetBundles compressed contents to conserve memory
    19.             bundle.Unload(false);
    20.            
    21.         } // memory is freed from the web stream (www.Dispose() gets called implicitly)
    22.     }
    23. }
    24.  
    Now I am no coding expert and I don't fully understand the code above but what I do know is that it works fine when it's calling the bundles from my local computer but not when I upload to the web server. I did change the BundleURL in the inspector to the path where the asset bundles are stored but nothing!

    http://www.blahblah.com/uploads/blah/AssetBundles

    A couple more questions:

    • Should I be using WWW.LoadFromCacheOrDownload ? I have a feeling that this would be better but I couldn't get this one working at all. My AssetBundles returned as Null when I tried this way.

    • Have I specified the URL correctly or do I need something before the htttp:// etc?

    • Am I using the correct loading script? I want to load the whole bundle and insert it into the scene not an asset specifically or level
    Any help would be appreciated. I'm pulling my hair out here!

    Ta
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. tattyswad

    tattyswad

    Joined:
    Sep 22, 2010
    Posts:
    106
    Interesting....

    Now I'm getting a decompression failure message but it's more than I was getting before! At least it's allowing it to look on the web server now.

    Another quick question, should I be able to download the assets stored on the web server directly into the Unity editor without having to publish etc?

    Thanks