简体   繁体   中英

Cannot load AssetBundle because “it is not compatible with the newer version of the Unity runtime”

I am trying to load an AssetBundle from a file, however I get the following error: The AssetBundle 'path\\to\\file' could not be loaded because it is not compatible with this newer version of the Unity runtime. Rebuild the AssetBundle to fix this error. The AssetBundle 'path\\to\\file' could not be loaded because it is not compatible with this newer version of the Unity runtime. Rebuild the AssetBundle to fix this error.

I build my AssetBundle as shown on the Unity wiki:

using UnityEditor;

namespace Editor
{
    public class CreateAssetBundles
    {
        [MenuItem("Assets/Build AssetBundles")]
        private static void BuildAllAssetBundles()
        {
            BuildPipeline.BuildAssetBundles("Assets/AssetBundles",
                BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
        }
    }
}

This generates a correct looking AssetBundle, the manifest file also looks fine.

I load the AssetBundle with the following code:

var assetBundle = AssetBundle.LoadFromFile(path);

Both the AssetBundle and the game are built with the same version of Unity, version 2017.3.1f1 (64 bit). I've also tried building both with the latest available beta build, but this did not resolve the issue.

Changing the BuildTarget to BuildTarget.StandaloneWindows64 also does not resolve the issue.

The Unity docs are outdated a bit on AssetBundles, since Unity 2017 they introduced an entire new assetbundle system, which is easier to use and works with an improved UI called the AssetBundle Browser

I've had issues myself when switching from Unity 5.x to 2017.x using assetbundles, and it actually required me to use the new assetbundle system, and build/load through that to get them to work again.

Get the Assetbundle browser:

  • Download the AssetBundle Browser from Unity's GitHub
  • Add the downloaded files to your Unity project
  • Go to Window
  • AssetBundle browser

Building an assetbundle:

here you will see two tabs, "configure" and "Build". Select the assetbundle you want to build by dragging a prefab of the object into the configure tab. you'll get a question asking if you want to build it as one big bundle or multiple seperate bundles, select whichever you prefer.

The Browser will also give a warning if multiple bundles share the same assets, and propose to make a single seperate bundle containing all shared resource, depending on how many and how big your bundles are this can save quite alot of space.

Then if you go to the "Build tab" you can select for which platform you want to build and the output path, along with some additional options such as compression type. Then all you have to do is click "Build" to build your new assetbundle compatible with unity 2017.x

Loading an Assetbundle:

Loading an assetbundle from a file is as simple as using the following piece of code: AssetBundle myAssetBundle = AssetBundle.LoadFromFile(path); You can also load assetbundles from Memory (taking in bytes) or load directly from a stream.

An additional bonus to the new AssetBundle browser is that you can customize it however you need All files can be found in /Assets/Editor/AssetBundleBrowser/ . for example I included the functionality to automatically upload all bundles to an FTP after its done building.

Edit: The Unity AssetBundle browser tool works for version 5.6 or higher.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM