Version: Unity 6.2 (6000.2)
Language : English
Handling dependencies between AssetBundles
Downloading AssetBundles

Optimizing AssetBundles

Loading AssetBundles can consume memory depending on 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
formats and access patterns.

AssetBundle memory overhead

When you load an AssetBundle, Unity allocates memory to both the assets contained in the AssetBundle and to its internal data. The main types of internal data for a loaded AssetBundle include:

TypeTrees

A TypeTree is an internal Unity data structure that describes the structure of data within a serialized binary object. It acts as a schema for Unity objects from the serialization system’s perspective.

Each serialized file in an AssetBundle contains a TypeTree for each object type in that file. You can use TypeTree information to deserialize files whose type definitions might have changed since serialization (for example, when fields are added, removed, or modified).

When Unity loads an AssetBundle, it loads all TypeTrees and keeps them in memory for the AssetBundle’s lifetime. TypeTree memory overhead depends on the number of unique object types loaded from AssetBundles and their complexity. Each AssetBundle contains a complete set of TypeTrees for its objects. Unity shares identical TypeTrees between AssetBundles to reduce memory usage when multiple AssetBundles are loaded.

Reduce TypeTree memory

You can reduce the memory requirements of AssetBundle TypeTrees in the following ways:

  • Disable TypeTrees. This excludes TypeTree information from an AssetBundle, and makes the AssetBundles smaller. However, without TypeTree information, when you load older AssetBundles with a newer version of Unity or make script changes in your project, you might get serialization errors or undefined behavior.
  • Use simple data types to reduce TypeTree complexity.

To test the impact that TypeTrees have on the size of AssetBundles, build them with and without TypeTrees disabled and compare their sizes. Use BuildAssetBundleOptions.DisableWriteTypeTree to disable TypeTrees in an AssetBundle.

Note: Some platforms require TypeTrees and ignore the DisableWriteTypeTree setting. Additionally, not all platforms support TypeTrees.

Table of contents

The table of contents is a map in the AssetBundle that you can use to look up each explicitly included asset by name. The size of the table of contents data increases with the number of assets explicitly included in the AssetBundle, and the length of the string names used to map them. The addressableNames property represents the string name, and if not defined the asset path is used instead.

To minimize the amount of memory dedicated to holding table of contents data, minimize the number of AssetBundles loaded at a given time.

The methods GetAllAssetNames and GetAllScenePaths expose the table of contents map.

Preload table

The preload table lists all objects that an asset depends on. When you load an asset from an AssetBundle, Unity uses this table to automatically load all required dependencies.

Each asset has its own preload table. For example, a prefabAn asset type that allows you to store a GameObject complete with components and properties. The prefab acts as a template from which you can create new object instances in the scene. More info
See in Glossary
’s preload table includes entries for all components attached to the prefab, referenced materials and textures, and any other assets the prefab uses.

Each preload entry uses 64 bits of memory and can reference objects in other AssetBundles.

When an asset references another asset that in turn references other assets, the preload table can become large because it contains duplicate entries where the assets share dependencies. If two assets both reference a third asset, then the preload tables of both assets contain entries to load the third asset.

Preload tables can contain duplicate entries where assets share dependencies. When an asset references another asset that in turn references other assets, Unity stores this information in each asset’s preload table. This can impact on memory usage.

You can reduce the impact of large preload tables in the following ways:

  • Projects that only use AssetBundles: Explicitly add any frequently-referenced asset that has many objects to an AssetBundle, so the preload information of that asset is shared.
  • Projects that use Addressables, or the Scriptable Build Pipeline: Avoid direct or indirect references from explicitly included assets to large hierarchies of objects.

Temporary in-memory AssetBundles

Unity manages memory efficiently, but temporary in-memory AssetBundles are created in the following scenarios:

  • LZMA-compressed bundles loaded via AssetBundle.LoadFromFile, LoadFromMemory, or LoadFromStream APIs.
  • AssetBundles downloaded without a version or hash.

Temporary files exist until reads complete and AssetBundle.Unload is called.

Caching considerations

  • LZ4 Default: Temporary in-memory bundles use LZ4 when Caching.compressionEnabled is true.
  • Uncompressed: When false, temporary bundles are uncompressed, potentially increasing RAM usage.

CRC checks and performance

CRC checks for chunk-based (LZ4) files don’t require full-file decompression but may affect load times.

CRC checks for LZMA files incur no additional cost, as full decompression is inherent. For more information, refer to Downloading AssetBundles.

Memory Profiler and AssetBundles

Use the Memory Profiler package to monitor memory usage and optimize AssetBundle loading workflows.

Additional resources

Handling dependencies between AssetBundles
Downloading AssetBundles