Hi! I have a problem with AssetBundle.
When using WWW to load an AssetBundle and get a object from AssetBundle.mainAsset, are there any side effects to call function AssetBundle.Unload(false) to free memory?
It seems like that if function Unload(false) is called, the object won’t be destroyed when the function AssetBundle.Unload(true) is called.
ps. The mainAsset is a Texture2D in my test case.
Example code:
public class TestUnload : MonoBehaviour {
void Start () {
StartCoroutine(TestLoad());
}
IEnumerator TestLoad() {
string BundleURL = "file://" + Application.streamingAssetsPath + "/texture.assetbundle";
using (WWW www = new WWW(BundleURL)) {
yield return www;
m_testObject = www.assetBundle.mainAsset;
www.assetBundle.Unload(false);
// wait 2 seconds for test
yield return new WaitForSeconds(2.0f);
www.assetBundle.Unload(true);
}
if (m_testObject != null)
{
Debug.Log("m_testObject != null");
}
else
{
Debug.Log("m_testObject == null");
}
}
Object m_testObject = null;
}
if www.assetBundle.Unload(false) is called → m_testObject != null
if www.assetBundle.Unload(false) is not called → m_testObject == null
Thanks