Skip to Content
Unity integrationUnity Object Pooling

Unity Object Pooling

Gnosis Engine uses a centralized pooling system for managing Unity GameObjects efficiently. This system is driven by the UnityObjectPoolRegistry and allows for both inspector-driven setup and dynamic, data-driven prewarming.

Code path: Runtime/GnosisEngine/Adapters/Unity/Pooling/UnityObjectPoolRegistry.cs.

Configuration

The registry maintains a list of UnityPoolEntryConfig objects. Each entry defines how a specific prefab should be pooled.

Properties

PropertyDescription
tagThe unique identifier for the pool (e.g., Explosion_Small).
prefabIdThe ID of the prefab in the Unity Asset Registry.
prewarmCountNumber of instances to instantiate during initialization.
shouldExpandWhether the pool should grow if all instances are currently active.
bucketNameOptional name of the parent transform for organizational purposes.

Data-Driven Prewarming

The pooling system can be configured dynamically via the Gnosis state store. This is typically done through the Configuration Service by loading a JSON file into Persistent.configuration.pooling.

Example: pooling.json

pooling.json
[ { "tag": "vfx_hit_spark", "prefabId": "vfx_hit_spark", "prewarmCount": 10, "shouldExpand": true, "bucketName": "VFX" } ]

Integration with Adapters

Many Unity adapters, such as the UnityAnimationAdapter, rely on this pooling system to manage particle effects and other transient GameObjects.

Lifecycle

  1. Awake/Enable: The registry ensures it is initialized.
  2. InitializePool: Creates the requested “buckets” (parent GameObjects) and instantiates the prewarm count for each entry.
  3. Get/Return: Standard pooling operations using IUnityObjectPoolRegistry interface.
Last updated on