- Home /
Question by
UbaidIqbal · Oct 13, 2020 at 10:08 AM ·
scripting problemassetbundlescripting beginnerassetsassetbundles
Why my Assets not loaded twice from the asset Bundle?
Hello, everyone! My Android game app size is more than 80 MB which I want to reduce through the Asset bundle. But the problem is that my assets bundle loaded only one time and I want to load it many times.
Please Help Me!
Script
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;
public class LoadAssetBundles : MonoBehaviour { AssetBundle myLoadedAssetbundle; public string path; public string colom1;
void Start()
{
LoadAssetBundle(path);
InstantiateSceneFromBundle(colom1);
}
void LoadAssetBundle(string bundleUrl)
{
myLoadedAssetbundle = AssetBundle.LoadFromFile(bundleUrl);
Debug.Log(myLoadedAssetbundle == null ? "Failed to load AssetBundle" : "AssetBundle succesfully loaded");
}
void InstantiateSceneFromBundle(string assetName)
{
var prefab = myLoadedAssetbundle.LoadAsset(assetName);
Instantiate(prefab);
}
}
Comment
Answer by p3k07 · Oct 13, 2020 at 07:31 PM
I found that using AssetBundle.Unload(true) clears the loaded bundle, then you can load something again.
Thank you for your answer. Please can you explain it more? I am new.