Madhu
Madhu

Reputation: 1229

Loading fbx files as Asset bundles in iPad - Memory Issue

In our iPad app we need to load FBX files(of size 1MB - 100MB) as asset bundles. I started testing with a FBX file of size 26MB and it creates an asset bundle of size 17MB. When I run the test scene to load this asset bundle in the iPad it load after around 1 minute. And then I get a memory warning. I monitored the memory using Xcode and it seems that memory usage increase from around 1MB to 65Mb and then just before the model show up memory increase to around 175MB at once. Below is my code.

I have seen similar issues posted by other users. But I didn't see a proper solution to it in any of these threads. As I read in these threads, I think the memory increases when uncompressing the asset bundle .But I don't understand why it goes unto around 170MB.

What can we do to reduce the memory usage?

public class CachingLoad : MonoBehaviour {
    public string BundleURL;
    public string AssetName;
    public int version;
 
    void Start() {
        StartCoroutine (DownloadAndCache());
    }
 
    IEnumerator DownloadAndCache (){
        // Wait for the Caching system to be ready
        while (!Caching.ready)
            yield return null;
       
        BundleURL = "http://10.30.3.228:8080/TestDownload/assetBundle1.unity3d";
        // Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
        using(WWW www = WWW.LoadFromCacheOrDownload (BundleURL, version)){
            yield return www;
            if (www.error != null)
                throw new Exception("WWW download had an error:" + www.error);
            AssetBundle bundle = www.assetBundle;
            if (AssetName == "")
                Instantiate(bundle.mainAsset);
            else
                Instantiate(bundle.Load(AssetName));
                    // Unload the AssetBundles compressed contents to conserve memory
                    bundle.Unload(false);
 
        } // memory is freed from the web stream (www.Dispose() gets called implicitly)
    }
}

Upvotes: 0

Views: 542

Answers (0)

Related Questions