以单位加载AssetBundle - 要实例化的对象为空

时间:2017-07-18 15:46:02

标签: c# unity3d vuforia

我正在将资产包加载到Image target(vuforia),并且它正在使用像立方体等小东西。但是我在加载更大的AssetBundle时遇到了问题。

using UnityEngine;
using System.Collections;
using System;

public class loadAsset1 : MonoBehaviour {

    void Start () {
        WWW www = new WWW("file:///Users/ewasniecinska/Desktop/bus");
        //Debug.Log (www.data);
        StartCoroutine(WaitForReq(www));
    }


    IEnumerator WaitForReq(WWW www)
    {
        while (!Caching.ready)
        yield return null;

        yield return www;

        AssetBundle bundle = www.assetBundle;

        if(www.error == null || www.error == "")
        {
            GameObject trump = (GameObject)bundle.LoadAsset("bus");
            Instantiate (trump, new Vector3 (0, 0, 0), Quaternion.identity);

            Debug.Log ("Received from Web: " + trump.gameObject);
        }
        else{
            Debug.Log(www.error);
        }
    }

}

但是当我尝试加载更大的资产时。我得到这样的错误,我认为sricpt并不等待资产加载,但我并不是100%肯定。

ArgumentException: The Object you want to instantiate is null.
UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:238)
UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:150)
UnityEngine.Object.Instantiate[GameObject] (UnityEngine.GameObject original, Vector3 position, Quaternion rotation) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:205)
loadAsset1+<WaitForReq>c__Iterator0.MoveNext () (at Assets/loadAsset1.cs:28)
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

1 个答案:

答案 0 :(得分:0)

请检查资产名称&#34; bus&#34;是否正确。由于资产名称不正确,我收到同样的错误。