Search Unity

  1. Tune in to get all the latest Unity news live from Berlin on June 19, 6pm CEST. Set up a YouTube reminder!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    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.