- Home /
NullReferenceException: Object reference not set to an instance of an object LoadFromCacheOrDownloadExample
I am trying to load a 3D object from a server. I have created a new project on Unity 2017.4.2f2 . Then added the c# script from the unity docs.
using UnityEngine; using System.Collections;
public class LoadFromCacheOrDownloadExample : MonoBehaviour { IEnumerator Start() { while (!Caching.ready) yield return null;
using (var www = WWW.LoadFromCacheOrDownload("http://myserver.com/myassetBundle.unity3d", 5))
{
yield return www;
if (!string.IsNullOrEmpty(www.error))
{
Debug.Log(www.error);
yield return null;
}
var myLoadedAssetBundle = www.assetBundle;
var asset = myLoadedAssetBundle.mainAsset;
}
}
}
Then named this script LoadFromCacheOrDownloadExample . After that I added the script to the camera. Then when I hit play I get this error.
NullReferenceException: Object reference not set to an instance of an object LoadFromCacheOrDownloadExample+c__Iterator0.MoveNext () (at Assets/LoadFromCacheOrDownloadExample.cs:21) UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
Can anyone help please?