UGTK / Toolkit / Utility Systems / Pooling System Completed
Pooling System
Summary
The Pooling System within the Unity Games Toolkit (UGTK) is designed to efficiently manage and reuse GameObject instances. This system is commonly used to optimize resource-intensive operations such as frequent instantiation and destruction of objects. It includes functionality for initializing pools, activating and deactivating objects, and dynamically expanding the pool when needed.
Content
Modules Dependencies
The Pooling System module does not have external dependencies within the UGTK. It can be used independently.
Setup
To set up the Pooling System, follow these steps:
-
Add
Poolerprefab in your scene: -
Configure the
Mn_Poolersetting thePoolable Object, thePool Stack, or changing ActiveParent or DeactiveParent:
How To Use
To use the Pooling System, use the following functions, called by code in an other script (Substitute myPooler with your pooler variable and T with the type of the component attached to your prefabObjectToPool):
- Get First Avaiable Object:
GameObject obj = myPooler.GetFirstAvaiableObject();
- Active an Object(
attachToActiveParentis setted to true by default, therefore, you can omit specifying it in the function):
GameObject obj;
bool attachToActiveParent;
myPooler.ActivateObject(obj, attachToActiveParent);
- Get First Avaiable
Tcomponent:
T comp = myPoolerGetFirstAvaiableComponent<T>();
- Active a component of
Ttype(attachToActiveParentis setted to true by default, therefore, you can omit specifying it in the function):
T comp;
bool attachToActiveParent;
myPooler.ActivateComponent(comp, attachToActiveParent)
- Has Element:
GameObject obj;
bool hasElement = myPooler.HasElement(obj);
- Has Component:
T comp;
bool hasElement = myPooler.HasComponent(comp);
Testing Scene
Open PoolableScene in the module's Debug/ folder and select Pooler User > 3DPooler.
The Editor Test Tools block needs Play mode - the pool is filled at runtime, and outside Play
the block says so rather than showing an empty one.
What to do, in order:
- Press GetFirstAvailableObject() — take one out a few times and watch Active objects climb.
- Set Amount to 5 and press Take N out, then Return every active object to the pool: the counter goes back to zero in one click.
- Take more than the pool holds (Pool Stack is 15 here).
- Return the same object twice from your own code.
- Set the active parent to an object that is inactive in the hierarchy.
Step 3 is the decision every pool has to make — grow, or refuse — and the answer changes how the game behaves under load. Step 5 is the classic false report: the object is taken, the counter says it is active, and nothing appears on screen because its parent is switched off.
Technical Info
The Pooling System module is composed of several key scripts and structures to manage and optimize GameObject instantiation and destruction.
Functs:
- PrepareObjectList: Initializes the object pool.
- ActivateObject: Activates a GameObject from the pool.
- ActivateComponent: Activates a Component from the pool.
- DeactivateObject: Deactivates a GameObject and returns it to the pool.
- DeactivateComponent: Deactivates a Component and returns it to the pool.
- GetFirstAvailableObject: Retrieves the first inactive GameObject, expanding the pool if necessary
- GetFirstAvailableComponent: Retrieves the first inactive Component, expanding the pool if necessary
- GetActiveObjects: Retrieves a list of all active GameObjects in the pool.
- GetActiveComponents: Retrieves a list of all active Components in the pool.
- HasElement: Checks if a GameObject is part of the pool.
- HasComponent: Checks if a Component is part of the pool.
© 2026 Marcello De Bonis. All rights reserved
Depends on 1
Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 2 modules in total.
UGTKengine within an engine


