- Home /
Question by
GARY_LEE_CH · Oct 29, 2018 at 03:39 AM ·
unity 5assetbundlememoryunloadunloadunusedassets
why UnloadUnusedAssets doesn't unload a asset?
HI Guys i use AssetBundle.LoadAllAssetsAsync api to get my Asset,but when i remove it,it always in memroy. Then i use LoadAllAssets api and UnloadUnusedAssets work.
ps: by unity5.6.5 and test in phone
here is my code:
public class test : MonoBehaviour {
public AssetBundle temp = null;
public AssetBundleRequest req;
void Start () {
temp = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "uialtas/340011.pkg"));
req = temp.LoadAllAssetsAsync(typeof(Sprite));
//temp.LoadAllAssets(typeof(Sprite));
//DestroyImmediate(img.gameObject);
//temp.Unload(false);
//StartCoroutine(OnExcuteUnloadUnusedAssets());
//Resources.UnloadUnusedAssets();
}
public void Clean() {
Resources.UnloadUnusedAssets();
}
public IEnumerator OnExcuteUnloadUnusedAssets()
{
yield return Resources.UnloadUnusedAssets();
//Debug.Log(1);
}
// Update is called once per frame
void Update () {
//if (req!=null&&req.isDone)
if(req!=null&& req.isDone)
{
req = null;
// Resources.UnloadUnusedAssets();
//UnityEditor.EditorUtility.UnloadUnusedAssetsImmediate();
if(temp!= null)
temp.Unload(false);
StartCoroutine(OnExcuteUnloadUnusedAssets());
//Resources.UnloadUnusedAssets();
}
}
}
assets-dont-unload.zip
(17.1 kB)
Comment