Unity generating corrupt asset bundles

I’ve been attempting to make use of asset bundles as part of my project, but for some reason unity is generating bundles that, when loading some (but not all) assets from the bundle, unity crashes.

I’m almost certain it’s a bug with unity, but searches for the error has returned nothing related on the internet. The objects in the bundle are simply prefabs with some serialized fields and references to sprites. It doesn’t seem to matter if the bundle is compressed or not. Changing or removing files from the bundle changes what assets cause unity to crash; there isn’t any single asset in particular causing it to crash. Below a certain number of assets I don’t seem to get a crash though.

I’ve tested in Unity 5.3.2, Unity 5.3.3p2, and even 5.4.0b8 and still no luck.

The editor log from the crash is as follows:

The code used to generate the asset bundle is fairly simple:

    [MenuItem("Scripts/Generate Asset Bundles")]
    static void MakeAssetBundles()
    {
        var assetNames = new List<string>();
        foreach (var f in Directory.GetFiles("Assets/PrefabFolder/LayerPrefabs/texture-Animations2", "*.prefab"))
            assetNames.Add(f);

        var b = new AssetBundleBuild();
        b.assetBundleName = "texture-animations2";
        b.assetNames = assetNames.ToArray();

        BuildPipeline.BuildAssetBundles("Assets/StreamingAssets", new []{b}, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.StandaloneWindows);

        Debug.Log("Done");
    }

As mentioned, though I specify uncompressed, this is mostly for time constraints. It still crashes with other bundle options.

And the code used to load the bundles to generate the crash is even simpler:

    void Start()
    {
        var path = Path.Combine(Application.streamingAssetsPath, "texture-animations2");
        var bundle = AssetBundle.LoadFromFile(path);

        bundle.LoadAllAssets();
    }

I’ve made a repo case and submitted it as a bug, case 776430. It’s not a small repo case though (250mb) as I needed a certain threshold of assets in order to generate a failing asset bundle, so I worry it will not get looked at in a timely fashion.

Anyone have any rough idea what could be causing this kind of failure? I’m at wits end.

Unfortunately I don’t have a fix for this issue, but I’ve finally come up with a workaround. By splitting the prefabs and sprites into separate asset bundles, unity will generate dependencies properly and output bundles that load correctly. Still no reason it should crash if they’re all in one bundle though…

Might be not related, but there are reals problems with “big” asset bundles besides the one you wrote about (I mean, with bundles that have a lot of assets inside) - in some cases, if you have such a bundle, it takes much more time to load an asset from it (i experienced 30x slowdown in some cases), and the only way to solve it was to split it up into several relatively small bundles.

Just warning

ive just spent the last two days dealing with this problem and dumbing this down to a list of 4 prefabs out of about 200 that i have and then finding the common factor between the two… turned out to be a script… specifically a field within the script…

PROGRAMMERS BE WARNED … Using a GUISkin object within a prefab that u plan to bundle… causes this corruption…

Atleast for me!

I hope this saves some one the 48 hrs it took me to track down :wink:

Edit: Im on Unity 5.5.0f3