Pool

Unity Pool utilities

In One Line

Where objects never die, they just take a break.

Overview

Pool is a resource control system. It will keep objects in memory to become ready to use.

Please read wiki page of Pool for details.

Package Info

display name

AceLand Pool

package name

latest version

1.2.0

namespace

dependencies

Why Use It

Unity Engine has it's own pool system. However you need to set everything, what to do on take from or return to pool, including instantiate and destroy.

This package has already created all necessary code for pool running in official method. And additionally add some management settings on it.

  • On Create

    • Instantiate OwnedItemPrefab

  • On Get

    • Invoke PoolItem.OnTakeFromPool()

    • Parent to Target Parent

    • Enable the game object

  • On Return

    • Invoke PoolItem.OnReturnToPool()

    • Disable the game object

    • Parent to Pool Parent

  • On Destroy

    • Destory the game object

Please read the Unity official document about Object Pool.


Pool Item

  • Create your Pool Item as an MonoBehaviour

  • Attach the component to GameObject and make it as a prefab


Pool Settings

  • kindly add a line, you can setup your pool now

Owned Item Prefab

IPoolItem that made as prefab

Pool Parent

Transform that hold objects not taken out

Target Parent

Transform That hold objects taken out

Pool Type

Stack or LinkedList, read Pool Type section for details

Prewarm Size

start and min size of the pool

Max Size

max size of the pool

Collection Checks

check that the objects being returned to the pool are the same type as those that were originally pooled. this may cause performance issue.


Pool Type

  • Small Pool:

    • Stack: More efficient in terms of memory and performance for small sizes; simple to implement.

    • Linked List: May incur unnecessary overhead; less common unless specific behavior is required.

  • Large Pool:

    • Stack: Efficient but may require careful management of memory and resizing. Suitable if LIFO access is necessary.

    • Linked List: More flexible for dynamic sizes; better for frequent insertions/deletions, but with higher memory overhead.


Create the Pool

Pool<T> where T : MonoBehaviour, IPoolItem


Use the Pool


Last updated