0

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.

AbdelAziz AbdelLatef
3,7527 gold badges28 silver badges55 bronze badges
asked Oct 4, 2019 at 10:55

1 Answer 1

0

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"));
}
answered Oct 4, 2019 at 11:18
Sign up to request clarification or add additional context in comments.

2 Comments

what's the solution of this?
Depends on how you want to handle errors. First thing I would do is confirm that is actually the problem. Put breakpoints on the code I've highlighted and see where the problem is, then you can decide how you want to handle it.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.