A downloadable tool

Download NowName your own price

A great way to improve performance is to use object pooling. This is when you keep a pool of objects in your scene to use as needed, rather than spawning in a new object every time you want one, which can cause pauses or stuttering as the object loads in. Creating new objects can be expensive, especially if they involve complex initialization or resource loading. This asset allows you to easily set up object pools by creating scriptable objects that reference a prefab, an amount you want to have available, and a string name that you can reference them by. 

Setup requires you to: create an object in your scene and assign the ObjectPool script; create your PoolData objects; then either populate the ObjectPool with your PoolData list OR point it to a Resources directory to load from (the folder Resources/PoolData will be created for you when you extract this asset into your Assets folder). Then, when you run your game, you can spawn your pool objects from any script with a single line of code:

ObjectPool.Instance.SpawnPoolObject(string poolName, Vector3 whereToSpawn, Vector3.one (size));

You can also include a xyz offsets in your request. If you use a Transform for whereToSpawn instead of a Vector3, spawned objects will take on the rotation of the transform; this is intended for projectiles and the like that might shoot out from an object's forward direction. You can send a maintainRotation variable if you don't want that functionality.

Additional instructions for using and customizing the code are in script comments. This asset was created with the intention of being used for highly repetitive effects like particle systems or projectiles. It was made for a 3D environment but could easily be tweaked for 2D. You can contact me at milkshakebattlecat@gmail.com if you need help getting it to support 2D or run into other problems.

Hope it helps. Good luck making your games!

CHANGELOG (UPDATED 3/10/2025):

  • Version 1.0.0 (Initial Release, Current)
    • Contains ObjectPool.cs, PoolData.cs, and the example script ObjectPoolUseExample.cs to show how it is used. Made to spawn object pool prefab lists at runtime. Prefab lists are stored in a dictionary and referenced by a key name which can be used to spawn the prefabs. The list of prefabs are inactive until called for use. ObjectPool.Instance.ReturnToPool(obj) can be used to return the object to an inactive state, making it available to be called again later. It's expected this function will be called by your own scripts. The ActivateEffects(obj) function also exists to make activation of spawned object scripts easy, just add your own logic there, or handle it some other way when the object is set to active. Examples of code from my own use cases has been provided.

Download

Download NowName your own price

Click download now to get access to the following files:

BATTLECAT_EasyObjectPool_v1-0-0.zip 9 kB

Leave a comment

Log in with itch.io to leave a comment.