AssetBundle files are an archive format that contains the following structures:
You can compress AssetBundle files in the following formats:
By default, Unity compresses the content section with LZMA and caches AssetBundles with LZ4.
Because different data compresses with different size savings, it’s best practice to rebuild your project with each supported option and measure the size difference.
If you download and store data with a custom caching solution you can use AssetBundle.RecompressAssetBundleAsync
to change compressionA method of storing data that reduces the amount of storage space it requires. See Texture Compression, Animation Compression, Audio Compression, Build Compression.
See in Glossary, for example to convert LZMA format AssetBundles to uncompressed or LZ4 format after download.
LZMA compresses the entire content section of the AssetBundle file as a single stream. This full content approach results in smaller file sizes than chunk-based LZ4 compression. LZMA is the preferred format for AssetBundles downloaded from a Content Delivery Network (CDN).
However, you must decompress the entire file into RAM to read an asset from archives compressed with LZMA. This approach works best when an AssetBundle contains assets that you want to load all at once. For example, packaging all assets for a character or sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary in one AssetBundle.
LZMA is the format used when calling BuildPipeline.BuildAssetBundles
with no specific compression specified, for example BuildAssetBundleOptions.None
.
Note: The Web platform doesn’t support LZMA compression. Use LZ4 compression instead. For more information, refer to AssetBundles in Web.
LZ4 uses a chunk based algorithm which decompresses the AssetBundle in chunks. While writing the AssetBundle, Unity individually compresses each 128 KB chunk of the content before saving it. This approach means the total AssetBundle file size is larger than LZMA compression. However, you can selectively retrieve and load just the chunks needed for a requested object, rather than decompressing the entire AssetBundle.
LZ4 has comparable loading times to uncompressed bundles with the added benefit of reduced size on disk. This is the format preferred by the AssetBundle cache, and it can also be a good choice for AssetBundles that you distribute as part of your installation or in other cases where size isn’t important.
To use this format, specify the flag BuildAssetBundleOptions.ChunkBasedCompression
when calling BuildPipeline.BuildAssetBundles
.
You can build AssetBundles so that the data is completely uncompressed. This creates a larger file download size, but faster load times once downloaded because no decompression is required. Uncompressed AssetBundles are helpful if only a few objects are loaded out of a larger AssetBundle.
Uncompressed AssetBundles are 16-byte aligned. To build uncompressed AssetBundles, specify the flag BuildAssetBundleOptions.UncompressedAssetBundle
when calling BuildPipeline.BuildAssetBundles
.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.