Search Unity

AssetBundles: Why does building one take so long? Any tips to speed it up?

Discussion in 'Editor & General Support' started by Dreamwriter, Jul 7, 2017.

  1. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    I’m building an asset bundle out of a single asset, an FBX. This is a complicated FBX, 200 megabytes and around 2500 submeshes (but only a few textures); it takes about 5 minutes for Unity to import it at first startup. In the end it's 28 files that are being built into the AssetBundle, with the textures and materials. But it takes about an hour to build that into an asset bundle, and I’m not compressing it at all! I’m building for Windows Standalone 64-bit, which is what my project is set to, so it doesn’t need to re-import to build the bundle.

    Code (CSharp):
    1. BuildPipeline.BuildAssetBundles(“Asset/AssetBundleOutput”, buildMap, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.StandaloneWindows64);
    So why does it take so long? The progress bar doesn’t say anything but “Building AssetBundles”; Windows 10 says Unity is using around 8.5% of my CPU, it’s not accessing the hard disk in a noticeable way, nothing else is happening, it’s only using 1GB of my 64GB memory, and I’ve got a fairly powerful CPU (i7-6900K at 3.2ghz).

    Any tips for speeding this up? I’ve tried setting Unity to “realtime” priority in Windows, didn’t seem to help.
     
    Last edited: Jul 7, 2017
  2. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    As a followup question, is there a way to make the AssetBundle builder only output the one single AssetBundle file that's needed? I get 4 files output (plus the .meta for each one) :

    AssetBundleOutput
    AssetBundleOutput.manifest
    mybundle
    mybundle.manifest

    But only the one file, mybundle, is needed. I could go through and delete the excess after it's built, but it seems there should be a way to control that. This is for a test tool that other people will run, so I'd like to minimize possible confusion.
     
  3. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    I managed to massively speed the bundle creation up, but...I'm still not sure why it was super super slow in the first place. To start, my FBX's tree in Unity shows up as the main object, and a whole buncha children under that - it's just one layer deep of children. So step one for speeding up the bundle creation: organize the FBX and those sub-meshes into a Prefab with 5 children, and all the sub-meshes are organized as children of those 5 children (I was doing this anyways, as part of the project is classifying the various bits). Second step: only include that Prefab in the AssetBundle, not the 12 materials and 12 textures that were created in the Import process (those end up as part of it because of dependencies anyways).

    These two steps sped up AssetBundle creation from one hour, to under a minute. If you just organize the FBX into a prefab, but still include the 12 materials and textures, it takes an hour. If you just add the raw FBX but none of the materials and textures, it takes an hour. But both of these steps makes it take a few seconds.

    Wish I knew why.