- Home /
assetBundle.mainAsset exception
Hi
I am writting code which loads a .unity3d file and uses it's asset to create a GameObject. I am builiding it for Android platform. I created a Cube prefab and then I built the assetBundle following this tutorial: http://docs.unity3d.com/Documentation/Manual/BuildingAssetBundles.html. Here is my code:
WWW www = new WWW ("file://sdcard/Cube.unity3d");
yield return www;
try {
GameObject obj = Instantiate(www.assetBundle.mainAsset) as GameObject;
}
catch (Exception ex) {
gameObject.guiText.text = "Exception: " + ex.Message;
}
The path "file://sdcard/Cube.unity3d" works because www.error is null, and i've checked that an error message appears if I use a wrong path. The problem occurs when I try to instantiate the mainAsset. Here, a exception is produced with the message: "Object reference not set to an instance of an object". I have checked that the exception is launched when trying to read the property mainAsset of the AssetBundle. I have tried to use assetbundle.Load instead, but the result is the same. I also tried to download the .unity3d file from a server instead using a local path.
Any idea?
Thank you
Your answer
Follow this Question
Related Questions
Download assetBundle from server 2 Answers
Assetbundle materials? 1 Answer
WWW UnknownHostException 2 Answers
Instantiate object with renderer disabled 1 Answer
Loading Assetbundles in Editor-script 2 Answers