Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

WebGL and AssetBundle DownLoad

Discussion in 'WebGL' started by xmjx_pl, Jan 25, 2019.

  1. xmjx_pl

    xmjx_pl

    Joined:
    Jan 25, 2019
    Posts:
    4
    I encountered a download problem for Asset Bundle on the WebGL platform. After packaging the resources loaded in the scenario, I used UnityWebRequest. GetAsset Bundle (url).
    Download resources. There was no problem running under Unity Editor. When I built this project, I have an error Info.
    Error message: Asset Bundle download is complete, but no data have been received.
    UnityWebRequest.responseCode:0
     
  2. xmjx_pl

    xmjx_pl

    Joined:
    Jan 25, 2019
    Posts:
    4
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.Networking;
    6.  
    7. public class CeateAsset : MonoBehaviour {
    8.  
    9.     private AssetBundle ab;
    10.     public Button m_StartBtn;
    11.     private string[] m_downloadurls;
    12.  
    13.  
    14.  
    15.     private void Awake()
    16.     {
    17.         Debug.Log("MonoBehaviour Awake");
    18.         //m_StartBtn.onClick.AddListener(() =>
    19.         //    { StartCoroutine(DownLoadAsset()); }
    20.         //);
    21.         m_StartBtn.onClick.AddListener(BtnOnClick);
    22.     }
    23.  
    24.     private void BtnOnClick()
    25.     {
    26.         Debug.Log("DownLoadBtn OnClick");
    27.         StartCoroutine(DownLoadAsset());
    28.     }
    29.  
    30.     IEnumerator DownLoadAsset()
    31.     {
    32.         Debug.Log("DownLoad IEnumerator Start");
    33.         UnityWebRequest unityWebRequest = UnityWebRequest.GetAssetBundle("http://192.168.1.236:8080/StreamingAssets/box.ab");
    34.         yield return unityWebRequest.Send();
    35.         Debug.Log("responseCode:" + unityWebRequest.responseCode);
    36.         if (unityWebRequest.isDone)
    37.         {
    38.             ab = (unityWebRequest.downloadHandler as DownloadHandlerAssetBundle).assetBundle;
    39.             Instantiate(ab.LoadAsset("boxs.prefab") as GameObject, Vector3.zero, new Quaternion(0, 0, 0, 0));
    40.         }
    41.     }
    42. }
     
  3. xmjx_pl

    xmjx_pl

    Joined:
    Jan 25, 2019
    Posts:
    4
  4. xmjx_pl

    xmjx_pl

    Joined:
    Jan 25, 2019
    Posts:
    4
    By the way,I used Unity 5.6.6f
     
  5. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    436
    @xmjx_pl Check if
    • You can download the file specified by the url via your browser to see if the url is actually valid - it likely is if it works in the editor
    • If the webgl player is accessed via https also request the download via https and provide a Certificate Handler accepting your certificate or any for test purposes
    • If the webgl player is accessed via www.<host> also access the bundle via www.<>.
    • Check the log for any CORS errors or warnings
    • Check the log for any out of memory or indexedDB or cache related error messages
     
  6. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    197
    Ran info the same issue, looking for solution.
     
  7. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    197