You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Oxters Wyzgowski edited this page Jun 11, 2019
·
1 revision
About Object Pool
The Object Pool is a class that lets you create and store many objects for reuse.
Create Pool
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.
Get Object
YourCustomType instance = pool.Get();
Get has optional parameters that allow you to place the object in the proper position, orientation, and scale.
Return Object
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.