-
Notifications
You must be signed in to change notification settings - Fork 5
Object Pool
Oxters Wyzgowski edited this page Jun 11, 2019
·
1 revision
The Object Pool is a class that lets you create and store many objects for reuse.
ObjectPool<YourCustomType> pool;
pool = new ObjectPool<YourCustomType>(prefab);
You need to replace YourCustomType here with your own class that inherits Component (so Transform and anything that inherits MonoBehaviour works too). There are more parameters in the constructor that change the behavior of the pool.
YourCustomType instance = pool.Get();
Get has optional parameters that allow you to place the object in the proper position, orientation, and scale.
pool.Return(instance);
If you have reuseObjectsInUse set to true, then you don't need to return old objects. The pool will reuse the first object after getting past the pool size.