Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 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.