For Unity GameObject resources, the ResSystem uses Addressables to manage instantiation and pooling. This is known as the GameObject Pool (GOP).
Initialization
Initialize a GOP using a keyName or an assetName (the Addressable resource name).
- maxCapacity: Maximum objects in pool. Excess objects are destroyed.
- assetName: The Addressable name used to fetch the prefab.
- defaultQuantity: Number of GameObjects to pre-load and instantiate into the pool.
Instantiation
- Synchronous:
InstantiateGameObject returns the GameObject immediately. You can also use the generic version InstantiateGameObject<T> to get a specific component directly. - Asynchronous:
InstantiateGameObjectAsync uses a callback to return the object once loading is complete. - autoRelease: If set to
true, the system attaches a listener so that when the object is Destroyed, the underlying Addressable resource is automatically released.
Unloading
Use PushGameObjectInPool to return a GameObject to its pool. If no pool exists for the object's name/key, an infinite pool is created automatically.
// Initialize a Bullet pool using Addressable name 'Bullet'
ResSystem.InitGameObjectPoolForAssetName("Bullet", 30, 30);
// Synchronous instantiation
GameObject bullet = ResSystem.InstantiateGameObject("Bullet");
// Synchronous instantiation with a component
Rigidbody rb = ResSystem.InstantiateGameObject<Rigidbody>("Bullet");
// Asynchronous instantiation
ResSystem.InstantiateGameObjectAsync("Bullet", (GameObject go) => {
go.transform.position = Vector3.zero;
});
// Return to pool
ResSystem.PushGameObjectInPool(bullet, "Bullet");