UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

optimization

[Build] Reducing Scene Size via Prefab Serialization Fixes

Solution

optimizationserializationprefabsperformancememory management

Unity 2021.3.x - Unity 6.3.x

Published 28 days ago

Issue

 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.

Explanation

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.

  1. Identify repetitive objects like ParticleSystem or high-density meshes that currently reside statically in the Hierarchy.
  2. Create a manager script with a GameObject field to hold the Prefab reference.
  3. Implement dynamic instantiation at runtime. This ensures only one copy of the Prefab is included in the build serialization data.
  4. 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.log to find the exact byte count contributed by serialization for each scene.
  • Implement Addressables to 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.

Content inspired by a Unity discussion post.