optimization
[Build] Reducing Scene Size via Prefab Serialization Fixes
Solution
Unity 2021.3.x - Unity 6.3.x
Published 28 days ago
Built scene files such as level0 or level1 often exhibit inflated file sizes because the serialization engine treats each Prefab instance as a unique, full data copy within the binary build data, rather than a shared reference.
The Unity build process performs a deep serialization pass on every object placed in a Scene. This causes Prefab instances to be stored as full data blobs rather than references, creating massive redundancy in the final executable data.
- Identify repetitive objects like
ParticleSystemor high-density meshes that currently reside statically in theHierarchy. - Create a manager script with a
GameObjectfield to hold thePrefabreference. - Implement dynamic instantiation at runtime. This ensures only one copy of the
Prefabis included in the build serialization data. - Open Build Settings and set the Compression Method to LZ4HC to pack repeated data patterns more efficiently.
Additional Tips
- Use the Build Report Tool or audit the
Editor.logto find the exact byte count contributed by serialization for each scene. - Implement
Addressablesto completely remove heavy assets from the scene serialization pass, loading them instead from external bundles.
TL;DR
Scene build size is reduced by preventing serialization redundancy through dynamic instantiation and LZ4HC compression.
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
[Canvas System] Duplicated UI Assets: Awake Initialization Skip[Prefab] Runtime Overhead of Removed Components in Variants[Build] Fix Extreme Loading Latency in Exported Asset Modules
Content inspired by a Unity discussion post.