https://github.com/yanicksenn/unity-pools
Unity3d package allowing to pool frequently used GameObjects.
https://github.com/yanicksenn/unity-pools
game-development open-source unity unity3d
Last synced: about 1 month ago
JSON representation
Unity3d package allowing to pool frequently used GameObjects.
- Host: GitHub
- URL: https://github.com/yanicksenn/unity-pools
- Owner: yanicksenn
- License: mit
- Created: 2022-03-16T16:26:13.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-19T21:27:58.000Z (over 4 years ago)
- Last Synced: 2025-07-19T22:39:56.810Z (12 months ago)
- Topics: game-development, open-source, unity, unity3d
- Language: C#
- Homepage:
- Size: 136 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Unity-Pools
Unity3d package allowing to pool frequently used GameObjects.
Feedback is welcome.
## Plug and Play
1. Open "Package Manager"
2. Choose "Add package from git URL..."
3. Use the HTTPS URL of this repository:
`https://github.com/yanicksenn/unity-pools.git`
4. Click "Add"
## Usage
- [Poolable](#user-content-poolable)
- [Pool](#user-content-pool)
- [Fetching](#user-content-fetching)
- [Instantiation](#user-content-instantiation)
### Creating Poolable
Assign the `Poolable` component to the `GameObject` that should be pooled.

Configuring the `OnFetchEvent` allows to listen and handle whenever an instance of this poolable is fetched from a `Pool`.
### Creating Pool
Assign the `Pool` component to the `GameObject` that should manage all instances.

Reference the `GameObject` with the `Poolable` component within the `Pooled Object` field and set the `Initial Capacity` to a desired number.
### Fetching
It is possible fetch instances from the `Pool` with the `Fetch()` method. It is possible to fetch as many instances as needed as long as the flag `Has Fixed Capacity` is not checked (Checking the flag prevents the creation of new instances when at capacity).
Instances that are no longer needed can made available again by deactivating the `GameObject` (`gameObject.SetActive(false)`).
```c#
public class MyGun : MonoBehaviour
{
[SerializeField]
private Pool myBullets;
[SerializeField]
private Transform myBore;
public void Shoot()
{
var instance = myPool.Fetch();
instance.transform.position = myBore.transform.position;
instance.transform.rotation = myBore.transform.rotation;
}
}
```
The instances will be created in the scene root (no parent). It is possible to change the default parent by specifying a transform in the `Default Parent` field.
### Instantiation
If a pool is allowed to grow and has no available instances an additional instance will be created. Therefore the pool capacity is increased by one. Sometimes it makes sense to additionally create a few more instance when growing. This can be accomplished by specifying the additional amount in the `Growing Capacity` field.