Pooling
Pooling provides a performant object pooling system for Unity that reduces instantiation overhead when spawning many objects. Built on patterns from Unity's open-source projects, it offers Factory and ComponentPool classes for easy integration, with support for prewarmining and efficient object reuse in games and real-time applications.
com.mushakushi.unitypooling Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/unitypooling.git 
README Markdown
Copy this to your project's README.md
## Installation
Add **Pooling** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/unitypooling.git
```
[](https://www.pkglnk.dev/pkg/unitypooling)README
Pooling
Pooling is a common pattern in video-games in order to increase performance when instantiating many objects. This pooling library takes hints from Unity's first (and last) open project, of which you can read their wiki article on pooling here.
Factory
Creates a factory for a component called MyComponent
public class MyComponentFactory : Factory<MyComponent>
{
public override MyComponent CreateInstance() {
return new MyComponent();
}
}
Component Pool
Create a pool for the MyComponentFactory above.
[CreateAssetMenu(fileName = "MyPool", menuName = "Pool/MyPool")]
public class MyPool : ComponentPool<MyComponent>
{
[field: SerializeField] private MyComponentFactory factory { get; set; }
[field: SerializeField] private int initialPoolSize { get; set; }
}
Example usage during runtime
public class RuntimeScript : MonoBehaviour
{
[SerializeField] private MyPool pool;
private void Awake()
{
pool = ScriptableObject.CreateInstance<MyPool>();
pool.Factory = ScriptableObject.CreateInstance<MyComponentFactory>();
}
private void Start()
{
pool.Prewarm(10);
MyComponent component = pool.Request();
// do things with the component then
pool.Return(component);
}
}
Comments
No comments yet. Be the first!
Sign in to join the conversation
Sign In