AssetBundle.LoadAsset 总是返回 NULL
AssetBundle.LoadAsset is always returning NULL
我无法从 Assest bundle 加载 Asset 作为 Gameobject。它返回 null
yield return www;
AssetBundle bundle = www.assetBundle;
if (www.error == null)
{
GameObject tv = (GameObject)bundle.LoadAsset("tv");
//yield return tv;
//GameObject santaasset = Instantiate(bundle.LoadAsset("tv", typeof(GameObject)) as GameObject);
Debug.Log(bundle); // returns tv
Debug.Log(tv);//return null
Instantiate(tv);
}
else
{
Debug.Log(www.error);
}
更新:
前
后
AssetBundle.LoadAsset
返回 null,因为您正在加载的 AssetBundle 中没有名为 "tv" 的对象。
1。确保拼写正确或您将正确的对象传递给 LoadAsset
函数。这是区分大小写的。
2。在构建 AssetBundle 之前,您必须确保您的对象 "tv" 已添加到 AssetBundle。
假设您的 AssetBundle 的名称是 "house"
,您要添加到其中的对象是 "tv"
,select "tv"
对象并更改"house"
的 AssetBundle 选项。请参阅下图以供参考:
在你的情况下,问题是 #1。您的 AssetBundle 的名称是 "tv"
,您想要加载一个名为 "1.obj"
的对象。将 "1"
传递给 LoadAsset
函数而不是 "tv"
。
我无法从 Assest bundle 加载 Asset 作为 Gameobject。它返回 null
yield return www;
AssetBundle bundle = www.assetBundle;
if (www.error == null)
{
GameObject tv = (GameObject)bundle.LoadAsset("tv");
//yield return tv;
//GameObject santaasset = Instantiate(bundle.LoadAsset("tv", typeof(GameObject)) as GameObject);
Debug.Log(bundle); // returns tv
Debug.Log(tv);//return null
Instantiate(tv);
}
else
{
Debug.Log(www.error);
}
更新:
前
AssetBundle.LoadAsset
返回 null,因为您正在加载的 AssetBundle 中没有名为 "tv" 的对象。
1。确保拼写正确或您将正确的对象传递给 LoadAsset
函数。这是区分大小写的。
2。在构建 AssetBundle 之前,您必须确保您的对象 "tv" 已添加到 AssetBundle。
假设您的 AssetBundle 的名称是 "house"
,您要添加到其中的对象是 "tv"
,select "tv"
对象并更改"house"
的 AssetBundle 选项。请参阅下图以供参考:
在你的情况下,问题是 #1。您的 AssetBundle 的名称是 "tv"
,您想要加载一个名为 "1.obj"
的对象。将 "1"
传递给 LoadAsset
函数而不是 "tv"
。