Hello.
I’m developing a game with large amount of graphical resources, and I’m using asset bundles to download those resources after the game is installed.
After the start of the game user sees the preloading scene, where asset bundles are downloaded and cached, in order to use them during the game.
The following code is used for caching asset bundles:
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
public class AssetBundleLoader : MonoBehaviour {
const string BaseURL = "http://192.168.1.46/AssetBundles/";
static List<string> assetBundleNames = new List<string>
{
// Asset bundle names
};
// Use this for initialization
IEnumerator Start () {
foreach (string assetBundleName in assetBundleNames)
{
string fullAssetBundlePath = BaseURL + assetBundleName;
using (
WWW download = WWW.LoadFromCacheOrDownload(fullAssetBundlePath, 1))
{
yield return download;
if (!string.IsNullOrEmpty(download.error))
continue;
AssetBundle bundle = download.assetBundle;
bundle.Unload(true);
}
}
yield return Resources.UnloadUnusedAssets ();
GC.Collect ();
}
}
The problem is that bundle.Unload(true)
doesn’t clear the memory. Thus, when I try to cache a lot of asset bundles in my scene, the game crashes due to Memory Pressure on iPad 2.
Any ideas on how to handle this would be useful.
Thank you.