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.
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:
AssetBundle.memoryBudgetKB
to control its size.
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.
You can reduce the memory requirements of AssetBundle TypeTrees in the following ways:
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.
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.
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:
Unity manages memory efficiently, but temporary in-memory AssetBundles are created in the following scenarios:
AssetBundle.LoadFromFile
, LoadFromMemory
, or LoadFromStream
APIs.Temporary files exist until reads complete and AssetBundle.Unload
is called.
Caching.compressionEnabled
is true
.false
, temporary bundles are uncompressed, potentially increasing RAM usage.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.
Use the Memory Profiler package to monitor memory usage and optimize AssetBundle loading workflows.