RefPool is a lightweight, high-performance pooling system for Unity 6 and above, designed to efficiently manage GameObjects through ScriptableObjects.
- Efficient GameObject pooling
- Works seamlessly with Unity 6 and above
- Uses ScriptableObjects for easy configuration and management
- Supports nested pooling through Groups for hierarchical pooling
In Unity, go to the Toolbar -> Window -> Package Management -> Package Manager
- In the Package Manager window, click the + button at the top left.
- Select Install package from git URL...
- Paste the following URL:
https://github.com/BluePixelDev/refpool.git
To create a Referenced Pool in your project:
- Go to the Project window and select a directory where you want to create the pool.
- Right-click in the directory and select: Create -> RefPool -> Pool
- Configure the pool using the Inspector. The Pool Asset is the primary endpoint for retrieving and releasing GameObjects.
Pools are used to manage individual collections of GameObjects. Each pool holds and manages a specific type of object.
Groups allow you to organize pools into hierarchical structures. You can nest multiple pools inside a group, enabling more granular control over different object types.
For example, you can create a pool for Debris and then use groups to separate Small Debris and Large Debris into separate pools.
RefPool also includes components that can be added to GameObjects for pooling functionality.
-
RefPooler
-
RefGroupPooler
-
RefSpawner (Used to spawn pooled objects)
-
RefPlacer (Used alongside
RefSpawner
to place objects.)
using BP.RefPool;
public class Example : MonoBehaviour
{
public RefResource resource; // Base class for both PoolAsset and PoolGroupAsset
public void Start() {
// Optionally, prepare the pool before using it
// resource.Prepare();
// Retrieve a pooled item (RefItem is a MonoBehaviour)
RefItem pooledItem = resource.Get()
// Manipulate the pooled item (e.g., set position, etc.)
pooledItem.transform.position = Vector3.zero;
// Once done, release the item back to the pool for reuse
pooledItem.Release()
}
}
In this example:
RefResource
is a base class used for both PoolAssets and PoolGroupAssets.Get()
retrieves a pooled item, which is a RefItem (a MonoBehaviour for managing the pooled objects).Release()
returns the object to the pool when no longer needed.
Contributions are welcome! If you find a bug or have a feature request, feel free to create an issue or submit a pull request.
- Fork the repository.
- Create a feature branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Create a new pull request.
I’ll review your changes and merge them after approval.
This project is licensed under the MIT License. See the LICENSE