Object Pool


In an attempt to make my current and future Unity games more efficient I developed an Object Pooling runtime utility, so rather than instantiating and destroying objects as they’re needed, the object pool will recycle existing objects as they’re no longer required. For the sake of convenience the Object Pool class is based off of the Singleton pattern, so to use it you don’t actually have to place a Game Object with the Object Pool component on it in a scene to use it. However, if you want to pre-load the Object Pool with prefabs you can, this does require you to manually place a Game Object with the Object Pool component on it in the scene in order to populate it in the hierarchy window.

For the sake of convenience, the Object Pool class uses functions that are almost parallel to Unity’s Destroy and Instantiate functions. So rather than using ‘GameObject.Instantiate’ you use ‘ObjectPool.Spawn’, with the new function returning a GameObject and its arguments mirroring those of the default Instantiate function. As for the ‘Destroy’ function, you can instead use ‘ObjectPool.Deactivate’, this function has two different sets of arguments, the default being to deactivate the specified object immediately, and the other being to deactivate it after a defined number of seconds.

Asset Store Page

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s