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

[Prefab] Runtime Overhead of Removed Components in Variants

Solution

optimizationserializationprefabsperformancecore

Unity 2018.3.x - Unity 6.3.x

Published Wed, Mar 25

Issue

 Developers often question if a Prefab Variant with removed components increases instantiation time or memory usage. The concern centers on whether Unity deserializes the base Prefab first and then performs a removal, causing CPU spikes during instantiation.

Removing components in a Prefab Variant is handled via delta serialization, resulting in zero runtime overhead during the instantiation process.

Explanation

Unity utilizes a instantiation process driven by a delta-based serialization system. When a Component is removed from a Prefab Variant, the variant stores a modification record indicating the removal rather than a runtime instruction to delete an existing object.

  1. During the build process, Unity serializes the hierarchy state to minimize runtime overhead.
  2. Upon instantiation, the engine resolves the hierarchy directly from the serialized deltas.
  3. The resulting GameObject at runtime does not contain the removed Component, and no CPU cycles are wasted on post-creation cleanup.

Additional Tips

  • While removing a Component is free, having thousands of deep overrides can slightly increase the time it takes for the engine to resolve the instantiation delta.
  • Use Object Pooling for high-frequency instantiation to bypass the overhead of reading serialized deltas from disk or memory.
  • Check the Overrides dropdown in the Editor to ensure your Prefab Variant only contains intended modifications.

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.