Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

WWWCached data can only be accessed using the assetBundle property!

Discussion in 'iOS and tvOS' started by simom85, Jul 24, 2012.

  1. simom85

    simom85

    Joined:
    May 27, 2010
    Posts:
    283
    Hi!! Why I get this error from my script exectued on Editor (Windows) ?

    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4. var www:WWW;
    5. var urlIos ="http://www.where-i-go.net/AssetBundles/CACA.unity3d";
    6. var bundle:AssetBundle;
    7. private var path:String;
    8. var prova:String;
    9.  
    10. function Start () {
    11. print (Application.dataPath);
    12.                    //Ottiene Asset Bundle
    13.                    www = WWW.LoadFromCacheOrDownload (urlIos,5001);
    14.                    yield www;
    15.                    bundle = www.assetBundle;
    16.                    //
    17.                    prova = GetiPhoneDocumentsPath (prova);
    18.                    moveAsset();
    19. }
    20.  
    21. function Update(){
    22.                   if(!bundle){
    23.                               Debug.Log(www.progress);
    24.                              }
    25.                  }
    26.  
    27. function GetiPhoneDocumentsPath (prova:String) {
    28.  
    29. path = Application.dataPath.Substring (0, Application.dataPath.Length - 5);
    30. path = path.Substring(0, path.LastIndexOf('/'));  
    31. return path + "/Assets/Documents";
    32.  
    33. }
    34.  
    35. function moveAsset()
    36. {
    37.     var cachedAssetBundle : String = prova+"/CACA.unity3d";
    38.     var cache = new System.IO.FileStream(cachedAssetBundle, System.IO.FileMode.Create);
    39.     cache.Write(www.bytes, 0, www.bytes.Length);
    40.     cache.Close();
    41.     Debug.Log(prova + "/CACA.unity3d");
    42.     Debug.Log("Cache saved: " + cachedAssetBundle);
    43.    
    44. }
    45.  
     
  2. Andrey-Postelzhuk

    Andrey-Postelzhuk

    Joined:
    Nov 26, 2013
    Posts:
    75
    Old thread. Anyway I'll reply.

    The problem is in moveAsset() function. If WWW object is used for loading asset bundle you can't call WWW.bytes or WWW.bytesDownloaded properties.

    What is the purpose of moveAsset() function? Unity have already cached bundle for you (WWW.LoadFromCacheOrDownload() function).
     
  3. daleth90

    daleth90

    Joined:
    Dec 15, 2014
    Posts:
    10