Search Unity

The unity3d editor no response after WWW.LoadFromCacheOrDownload?

Discussion in 'Scripting' started by Usmith, Apr 7, 2013.

  1. Usmith

    Usmith

    Joined:
    Apr 7, 2013
    Posts:
    20
    Hi all, has anyone seen this problem before?
    The things is like this:
    We are developing a game that target platform is android, the game has a lot of resources, not only the total size, but also file amount. At first we simply put the resources under Assets\Resources, and use Resources.Load() to use them. This is quite easy to use. But as the project moving forward, we found it's impossible to package the whole assets to a single package file , the package size is 100MB+ now! Naturally we want to load the resources dynamically from a remote server by using WWW.LoadFromCacheOrDownload(), so we tested it, and we found there are 400+ HTTP requests at the same time. So we have to change our strategy , the plan is as following: 1.package the whole resources into a file, 2.the client downloads the file and unpackage it to a local data folder. 3. preload resources from local folder into unity cache . 4. using WWW.LoadFromCacheOrDownload() to access.

    The problem started to show at step 3, we use WWW.LoadFromCacheOrDownload() to preload the assets to unity cache, and during the loading process, all kinds of strange problems happened. After all, all resources has been preloaded to the cache. But when we using the cache, a strange problem happened, the editor always goes no response, debuging the code, I found it's around the code WWW.LoadFromCacheOrDownload().
    There's a function loadObj() like this:
    Code (csharp):
    1.  
    2.  
    3. Object loadObj(string path)
    4.     {
    5.         Object obj = Resources.Load(path);//Find resources from inner package      
    6.         if (null == obj)
    7.         {
    8.             path = GET_CACHING_PATH(path);//Get the caching path
    9.             WWW www = null;
    10.             if (!Caching.IsVersionCached(path, THE_VERSION))
    11.             {
    12.                                 //This never happened , because everything has been cached.
    13.                 throw new System.Exception("Resource not cached.");
    14.             }
    15.             else
    16.             {
    17.                 www = WWW.LoadFromCacheOrDownload(path, DEFAULT_VERSION);
    18.             }
    19.            
    20.             if (string.IsNullOrEmpty(www.error))
    21.             {
    22.                 obj = www.assetBundle.mainAsset;//This code makes the editor no response.Actually it's www.assetsBundle
    23.                 www.assetBundle.Unload(false);
    24.             }
    25.             else
    26.             {
    27.                 Debug.LogError("Load Failed: " + www.error);
    28.             }
    29.         }
    30.        
    31.         return obj;
    32.     }
    33.  
    34.  
    35.  
    I'm pretty sure that all resources I need is cached because that exception never fired, and since the resource is cached , WWW.LoadFromCacheOrDownload() returns a www object immediately, so I could access it's property immediately, but, like all I said, the editor just went no response, I have to kill the editor process and restart it.
    I googled, but no answer for this, anyone can help?
     
    Last edited: Apr 7, 2013