You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use ObjectPool to instantiate game objects during loading time and not during gameplay. This version allows you to have multiple pools in your game, so you can have a global one that won't be destroyed between scenes, and some level-specific ones.
Use ObjectPool to instantiate game objects during loading time and not during gameplay.
This version allows you to have multiple pools in your game, so you can have a global one that won't be destroyed between scenes, and some level-specific ones.
To get it persistent between scenes attach a DontDestroyOnLoad script on the same Game Object.
Usage
Basic
Use the provided Prefab or put the ObjectPool script in a game object that won't be destroyed during your game, and add the prefabs you want in the list in the inspector. Set the buffered amount, the default parent (optional), and you're set.
Retrieve the object pool with ObjectPool.GetObjectPool()
Retrieve an already instantiated game object and use it in your game with GetFromPool("prefabName") on the object pool.
To pool and deactivate a previously instantiated and retrieved game object, use
ObjectPool.GetObjectPool().Pool(usedObject)
Multiple pools
If you want to have multiple pools on your game, you can specify a different id on the object pool inspector and use it when retrieving the object pool
ObjectPool.GetObjectPool("myOtherPool")
Generic method
As you would do with the Instantiate<T> version, you can automatically have a call of GetComponent<T> from inside the pool.
You can now use a list of IDs for both pools and objects as you would do with enum, but without the need of creating ones.
Add FRP_DATA_LIST in the Scripting Define Symbols and make sure the StringDataList package is imported (it's defined in the dependencies so should be there by default when importing this version of the object pool).
For this IDs to be known, create in a Resources/datalist folder of your project:
a PoolId.txt file for pool ids
a ObjectId.txt file for the objects ids.
You can add one or the other or both, it's up to you.
About
Use ObjectPool to instantiate game objects during loading time and not during gameplay. This version allows you to have multiple pools in your game, so you can have a global one that won't be destroyed between scenes, and some level-specific ones.