【问题标题】:Unity - Loading asset bundles - File can't be loaded because it is not compatible with this platformUnity - 加载资产包 - 文件无法加载,因为它与此平台不兼容
【发布时间】:2016-10-28 15:45:08
【问题描述】:

我正在开发从我的 htdocs 加载资产包的 Unity 应用程序,该应用程序将在 iPhone 上运行。

当内容获取工作(afaik)时,加载停止大约一半,Xcode 吐出以下错误:

Unloading 3 Unused Serialized files (Serialized files now loaded: 0)
UnloadTime: 13.037000 ms

Unloading 50 unused Assets to reduce memory usage. Loaded Objects now: 733.
Total: 10.006415 ms (FindLiveObjects: 0.065750 ms CreateObjectMapping: 0.033250 ms MarkObjects: 0.951208 ms  DeleteObjects: 8.955166 ms)

2016-10-26 18:34:58.882 CookieJarApp[6245:1953469] You are using download over http. Currently unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
Asset bundle [ios_cookie_prefabs] loaded.
<CoLoadAssetBundle>d__20:MoveNext()

(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)

The file can not be loaded because it was created for another build target that is not compatible with this platform.
Please make sure to build AssetBundles using the build target platform that it is used by.
File's Build target is: 13

<CoLoadAssetBundle>d__20:MoveNext()

[ line 907] 
(Filename:  Line: 907)

The AssetBundle 'http://192.168.1.241:80/CookieJarApp_test/ios_cookie_prefabs' can't be loaded because it was not built with the right version or build target.
<CoLoadAssetBundle>d__20:MoveNext()

[ line 406] 
(Filename:  Line: 406)

NullReferenceException: A null value was found where an object instance was required.
  at AssetBundleController.GetGameObject (System.String bundleID, System.String objectName) [0x00000] in <filename unknown>:0 
  at AssetBundleController.UnloadAll () [0x00000] in <filename unknown>:0 
  at Loader+<LoadPrefabs>c__AnonStorey22.<>m__15 (UnityEngine.AssetBundle bundle) [0x00000] in <filename unknown>:0 
  at AssetBundleController+<CoLoadAssetBundle>d__20.MoveNext () [0x00000] in <filename unknown>:0 

(Filename: currently not available on il2cpp Line: -1)

但是,我使用 Build Settings 中选择的 iOS 平台构建了预制件(本身就是另一个游戏)。

有人告诉我,资产包不同,还有什么我可以尝试的吗?

这是CoLoadAssetBundle 函数:

// Start a download of the given URL
        WWW www = new WWW(url);

        while (!www.isDone)
        {
            Debug.Log("[" + bundleId + "] Progress:" + www.progress * 100f + "%");
            yield return null;
        }

        if (string.IsNullOrEmpty(www.error))
        {
            Debug.Log("Asset bundle [" + bundleId + "] loaded.");
            m_assetBundleList.Add(new AssetBundleStruct(bundleId, www.assetBundle));
        }
        else
        {
            Debug.Log("Asset bundle [" + bundleId + "] not loaded!\n[" + www.error + "]");
        }

        www.Dispose();

【问题讨论】:

  • 您用来加载资源包的代码在哪里?
  • @Programmer,啊,现在不在我身边,我明天回来时必须更新这个。 FWIW,我们已经使用相同的代码创建了至少一个可以完美运行的 Asset Bundle,我认为那里不会有问题。
  • @Programmer,我已经添加了一些代码,希望对您有所帮助。
  • 我说的是用于从设备加载它的代码,而不是用于构建它的代码。同时,请看我的回答。
  • @Programmer,我的错,对不起。我已经编辑了问题。

标签: xcode unity3d


【解决方案1】:

在为 iOS 构建 AssetBundle 之后,您必须强制缓存以使用它的新副本。

如果您使用的是WWW API,您可以通过提供第二个参数 (int version) 来做到这一点。

WWW.LoadFromCacheOrDownload(url, 1); 

如果使用UnityWebRequest API,您必须将第三个参数(uint version)提供给它的静态构造函数。

UnityWebRequest www = UnityWebRequest.GetAssetBundle(url, 0, 1);

编辑

使用您编辑的问题和代码,您需要使用我在此答案中提到的第一种方法。简单替换

WWW www = new WWW(url); WWW www = WWW.LoadFromCacheOrDownload(url, 1);

【讨论】:

  • 我将该部分更改为您建议的代码(谢谢,顺便说一句)。但是,它仍然给我同样的错误。
  • 这很奇怪。为什么不将1 替换为2 看看会发生什么。在构建新应用之前,还要从 iOS 中卸载旧应用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多