Hi
I am trying import a 3D Object from Web. I was able to typing my code C#, but I have a Warning Messsage. Please, What is it wrong ?
Message:
ArgumentException: The Object you want to instantiate is null.
UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:239)
UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:151)
UnityEngine.Object.Instantiate[GameObject] (UnityEngine.GameObject original, Vector3 position, Quaternion rotation) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:206)
installer+<WaitForReq>c__Iterator0.MoveNext () (at Assets/Scripts/Store/installer.cs:23)
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class installer : MonoBehaviour {
// Use this for initialization
void Start () {
string url = "https://www.mywebsite.com/AssetBundles/wheel";
WWW www = new WWW(url);
StartCoroutine(WaitForReq(www));
}
IEnumerator WaitForReq(WWW www)
{
yield return www;
AssetBundle bundle = www.assetBundle;
if(www.error == null)
{
GameObject wheel = (GameObject)bundle.LoadAsset("wheel");
Instantiate (wheel, new Vector3 (260, 240, 160), Quaternion.identity);
Debug.Log ("Received from Web: " + www.data);
}
else{
Debug.Log(www.error);
}
}
}
Thank You
Just to clarify things, in Unity speak, “importing a 3D object” is something only the editor does, and then you use it in a GameObject context however you like.
It appears what you are doing is loading an asset bundle (something created in the Unity editor from your prefabs and other assets) from the web and instantiating a prefab within it called “wheel.”
Therefore you need to start with the most obvious steps of debugging this process:
-
are you making the asset bundle properly (does it even have the wheel Prefab in it?) Look in the manifest file created by Unity when you make the asset bundle.
-
are you targeting the right platform? see Unity documentation for which asset bundles can be loaded by what targets but it is always best to load iOS bundles in iOS, PC bundles on PC, etc.
-
are you reading X number of bytes down from the WWW call? Look at the data.Length, see if it is what you expect
That should give you some steps to try.
Sounds very much like you are failing to load the asset. If it was a problem with the asset bundle itself, you would get a different error or an error on a different line.
I would try bundle.GetAllAssetNames, just to check what is actually in the file. It could be as simple as a capitalization error.
1 Like
First, Thanks Kurt Dekker and Kiwasi by collective force
I did solve my problem. I would like share knowledge.
1) I did the prefab name of ( wheel ) to ( cube ).
2) I did the BuildTarget into build script.
BuildPipeline.BuildAssetBundles("Assets/AssetBundles/", BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
3) I haven’t a warning message more and I can see my cube on my screen.
Received from Web: UnityFS
UnityEngine.Debug:Log(Object)
<WaitForReq>c__Iterator0:MoveNext() (at Assets/exibirAssetBundlers.cs:26)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
4) I wrote a new code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class exibirAssetBundlers : MonoBehaviour {
// Use this for initialization
void Start () {
string url = "http://localhost/AssetBundles/cube";
WWW www = new WWW(url);
//Debug.Log (www.data);
StartCoroutine(WaitForReq(www));
}
IEnumerator WaitForReq(WWW www)
{
yield return www;
AssetBundle bundle = www.assetBundle;
if(www.error == null)
{
GameObject cube = (GameObject)bundle.LoadAsset("cube");
Instantiate (cube, new Vector3 (0, 0, 0), Quaternion.identity);
Debug.Log ("Received from Web: " + cube.gameObject);
}
else{
Debug.Log(www.error);
}
}
}
Thank You my friends.
2 Likes