Search Unity

  1. We want you to join us at GDC this year! Take a peek at all of the events we will be hosting during the week of GDC.
    Dismiss Notice
  2. Tell us about your experience here and you’ll get early access to the 2018 Game Studios report + more goodies.
    Dismiss Notice
  3. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  5. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice

Loading external AssetBundles

Discussion in 'Scripting' started by arfishstudios, Sep 13, 2017.

  1. arfishstudios

    arfishstudios

    Joined:
    Sep 13, 2017
    Posts:
    2
    Hi

    I´m trying to load external assets bundles with www.LoadFromCacheOrDownload, but can’t figure out how to load TextAsset with .text or .bytes content.

    Everything works when downloading assets containing a GameObject prefab, like this:

    AssetBundle bundle = www.assetBundle;
    AssetBundleRequest request = bundle.LoadAssetAsync<GameObject> (”house”);
    yield return request;
    GameObject go = request.asset as GameObject;
    Instantiate<GameObject> (go);


    But when I try the same with an Asset Bundle containing a TextAsset it only throws NullReferenceException errors.
    Have tried to access the text using both .text and .bytes.

    This is the code:

    AssetBundle bundle = www.assetBundle;
    AssetBundleRequest request = bundle.LoadAssetAsync<TextAsset> (”123456c”);
    yield return request;

    TextAsset ta = request.asset as TextAsset;

    // Get the byte data
    byte[] encryptedData = ta.bytes; // (this is line 48, throwing the error)


    This is the Console error message (when running on an Android device):

    AndroidPlayer(Sony_D5803@192.168.10.100)</i> NullReferenceException: Object reference not set to an instance of an object

    at LoadObjectFromBundle+<DownloadObject>c__Iterator0.MoveNext () [0x00141] in /Users/Shared/Unity_2017/VRPlace/Assets/LoadObjectFromBundle.cs:48

    at UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) [0x00028] in /Users/builduser/buildslave/unity/build/Runtime/Export/Coroutines.cs:17

    (Filename: /Users/Shared/Unity_2017/VRPlace/Assets/LoadObjectFromBundle.cs Line: 48)


    The size of the asset bundle is about 9 MB, and it does only contain one asset.

    Does any one have an Idea what´s going on?
     
  2. arfishstudios

    arfishstudios

    Joined:
    Sep 13, 2017
    Posts:
    2
    SOLVED. Using UnityWebRequest instead of LoadFromCacheOrDownload to download the file fixed it.