Skip to content

Documentation

Venomous edited this page Feb 6, 2019 · 26 revisions

How to setup UnityObjectPooler in your Unity project?

Step 1).

Add ObjectPool.cs to your project assets folder.


Step 2).

Use the ObjectPool's static methods

ObjectPool can be accessed at all times.

ObjectPool.Clear(); // Clears the pool (should be used on scene reload or new scene load because its static)

ObjectPool.Add(poolable); // Takes any Unity Component type

ObjectPool.Add<yourtype>(poolable); // Same as non generic Add but a base class can be used when poolable is a subclass.

For example when you have:

public class Base { }

public class Derived : Base { }

ObjectPool.Add<Base>(poolable);

poolable is of type Derived, but you can also retrieve it like Get<Base>();

ObjectPool.Get<yourtype>(); // Will return one of your type from the pool (null if none in the pool)

ObjectPool.GetCustom<yourtype>(f => f.Score == 5); // This will return your Component to the type passed if one is found based on your custom lambda criteria (as an example i get the type with score of 5)

ObjectPool.GetAmountInPool<yourtype>(); // Retrieves an int based on how many of this type are in the pool

Clone this wiki locally