Reputation: 19
I'm trying to load assetbundle form server.
My assetbunles is live on URL. Right now my game in editor on webgl platform.
My load assetbundles script:
[Obsolete]
IEnumerator Start()
{
while (!Caching.ready)
yield return null;
using (var www = WWW.LoadFromCacheOrDownload("http://dev71.onlinetestingserver.com/assetBundles/cube", 5))
{
yield return www;
if (!string.IsNullOrEmpty(www.error))
{
Debug.Log(www.error);
yield return null;
}
var myLoadedAssetBundle = www.assetBundle;
var asset = myLoadedAssetBundle.mainAsset;
Instantiate(www.assetBundle.LoadAsset("cube"));
}
}
but it gives error:
NullReferenceException: Object reference not set to an instance of an object LoadAssetBundles+d__0.MoveNext () (at Assets/LoadAssetBundles.cs:76) UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)
I just want that when I play my game, it loads asset bundle perfectly. I already created asset bundles.
Upvotes: 0
Views: 1513
Reputation: 11909
You aren't checking that for null.
using (var www = WWW.LoadFromCacheOrDownload("http://dev71.onlinetestingserver.com/assetBundles/cube", 5))
{
yield return www; <--- www MIGHT BE NULL
if (!string.IsNullOrEmpty(www.error))
{
Debug.Log(www.error);
yield return null;
}
var myLoadedAssetBundle = www.assetBundle;
var asset = myLoadedAssetBundle.mainAsset; <--- www.assetBundle MIGHT BE NULL
Instantiate(www.assetBundle.LoadAsset("cube"));
}
Upvotes: 0