Unclaimed Package Is this your package? Claim it to unlock full analytics and manage your listing.
Claim This Package

Install via UPM

Add to Unity Package Manager using this URL

https://www.pkglnk.dev/unitypooling.git
Pooling

README Markdown

Copy this to your project's README.md

Style
Preview
pkglnk installs badge
## 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
```

[![pkglnk](https://www.pkglnk.dev/badge/unitypooling.svg?style=pkglnk)](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!