Search Unity

  1. 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
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    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.