Question by
opponent019 · Mar 13, 2017 at 06:20 AM ·
assetbundleruntimeparticlesystemimportingasset bundle
Importing particles at runtime with Asset Bundles
Hi, I'm trying to import a particle system using Unity Asset Bundles and it works in the editor but after building for Android (the whole project is just for Android) it stops working saying that what I'm trying to instantiate is null. Here's the code: IEnumerator GetAssetBundle(string assetName) { // Wait for the Caching system to be ready while (!Caching.ready) yield return null;
// Load the files file from Cache if it exists with the same version or download and store it in the cache
using (WWW www = WWW.LoadFromCacheOrDownload("file:///" + Application.persistentDataPath + "/" + assetName, 0)) { //looking for an asset bundle
yield return www;
if (www.error != null) {
throw new UnityException("WWW download had an error:" + www.error);
} else { // If it's an asset bundle
AssetBundle bundle = www.assetBundle;
var obj = bundle.LoadAsset(assetName) as GameObject;
model = Instantiate(obj);
model.name = assetName;
Debug.Log("Asset Bundle's model instantiated");
bundle.Unload(false); // Unload the AssetBundles compressed contents to conserve memory
FixShader();
}
} // memory is freed from the web stream (www.Dispose() gets called implicitly)
yield break;
}
Was wondering if it's possible at all of I'm doing something wrong? Thanks!
P.S. Also asked in the forums but no response so far so thought of trying my luck here.
Comment