{"id":16209906,"url":"https://github.com/annulusgames/upools","last_synced_at":"2025-08-31T14:06:59.953Z","repository":{"id":202882775,"uuid":"708339200","full_name":"annulusgames/uPools","owner":"annulusgames","description":"A lightweight and flexible object pooling system for Unity","archived":false,"fork":false,"pushed_at":"2024-07-06T13:47:26.000Z","size":79,"stargazers_count":168,"open_issues_count":1,"forks_count":12,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-18T16:48:57.024Z","etag":null,"topics":["csharp","object-pooling","pool","unity"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/annulusgames.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-22T09:08:07.000Z","updated_at":"2025-06-18T09:06:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"79d51ebe-2648-4733-bdee-aa8e2425060e","html_url":"https://github.com/annulusgames/uPools","commit_stats":null,"previous_names":["annulusgames/upools","yn01dev/upools","yn01-dev/upools","nuskey8/upools"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/annulusgames/uPools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FuPools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FuPools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FuPools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FuPools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/annulusgames","download_url":"https://codeload.github.com/annulusgames/uPools/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FuPools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272988919,"owners_count":25026961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","object-pooling","pool","unity"],"created_at":"2024-10-10T10:33:57.147Z","updated_at":"2025-08-31T14:06:59.916Z","avatar_url":"https://github.com/annulusgames.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# uPools\n A lightweight and flexible object pooling system for Unity\n\n\u003cimg width=\"100%\" src=\"https://github.com/AnnulusGames/uPools/blob/main/Assets/uPools/Documentation~/Header.png\"\u003e\n\n[![license](https://img.shields.io/badge/LICENSE-MIT-green.svg)](LICENSE)\n\n[日本語版READMEはこちら](README_JA.md)\n\n## Overview\n\nuPools is a library that provides object pooling functionality for Unity. It includes various classes for object pooling, such as a generic `ObjectPool` and a specialized `GameObjectPool` for GameObjects. You can also create your custom object pools by inheriting from the `ObjectPoolBase` class. Additionally, it offers the convenience of object pooling using `SharedGameObjectPool`.\n\nFurthermore, it provides support for asynchronous object pooling using UniTask and object pooling with Addressables.\n\n## Features\n\n* Numerous classes for object pooling in Unity\n* Generic object pooling with `ObjectPool`\n* Pooling for GameObjects with `GameObjectPool`\n* `SharedGameObjectPool` that can replace `Instantiate` and `Destroy`\n* Callback handling with `IPoolCallbackReceiver`\n* Asynchronous object pooling with UniTask\n* Object pooling with Addressables using `AddressableGameObjectPool`\n\n## Setup\n\n### Requirements\n\n* Unity 2019.4 or newer\n\n### Installation\n\n1. Open the Package Manager from Window \u003e Package Manager.\n2. Click the \"+\" button, then select \"Add package from git URL.\"\n3. Enter the following URL:\n\n```\nhttps://github.com/AnnulusGames/uPools.git?path=/Assets/uPools\n```\n\nAlternatively, open the Packages/manifest.json file and add the following to the dependencies block:\n\n```json\n{\n    \"dependencies\": {\n        \"com.annulusgames.u-pools\" : \"https://github.com/AnnulusGames/uPools.git?path=/Assets/uPools\"\n    }\n}\n```\n\n## Quick Start\n\nYou can implement object pooling by simply replacing `Instantiate()` with `SharedGameObjectPool.Rent()` and `Destroy()` with `SharedGameObjectPool.Return()`.\n\n```cs\nusing UnityEngine;\nusing uPools;\n\npublic class Example : MonoBehaviour\n{\n    [SerializeField] GameObject prefab;\n\n    void Start()\n    {\n        // Pre-warm objects in advance (additional objects are created automatically)\n        SharedGameObjectPool.Prewarm(prefab, 10);\n\n        // Retrieve objects from the pool\n        var instance = SharedGameObjectPool.Rent(prefab);\n\n        // Return the object to the pool after use\n        SharedGameObjectPool.Return(instance);\n    }\n}\n```\n\nThis is the simplest way to implement object pooling. If you need more fine-grained control, you can explore the following methods.\n\n## Pooling Regular Classes\n\nTo pool regular classes, you can create an object pool using `ObjectPool\u003cT\u003e`.\n\n```cs\nclass PooledObject { }\n\nvar pool = new ObjectPool\u003cPooledObject\u003e(\n    createFunc: () =\u003e new PooledObject(), // provide object creation using a Func\u003cT\u003e\n    onRent: instance =\u003e { }, // actions on Rent (optional)\n    onReturn: instance =\u003e { }, // actions on Return  (optional)\n    onDestroy: instance =\u003e { } // actions when the pool is destroyed (optional)\n)\n\n// Pre-warm the pool with objects\npool.Prewarm(10);\n\n// Use Rent() to retrieve an object, and Return() to return it to the pool\nvar instance = pool.Rent();\npool.Return(instance);\n\n// Get the number of objects in the pool\nvar count = pool.Count;\n\n// Clear all objects in the pool\npool.Clear();\n\n// Dispose of the pool with Dispose()\npool.Dispose();\n```\n\n\u003e **Warning**\n\u003e Note that object pools are not thread-safe.\n\n## Pooling GameObjects\n\nFor pooling GameObjects, a dedicated `GameObjectPool` is provided.\n\n```cs\n// GameObject prefab\nGameObject original;\n\nvar pool = new GameObjectPool(original);\n\n// Use Rent() to retrieve an object\nvar instance1 = pool.Rent();\n\n// You can specify position, rotation, and parent Transform when retrieving\nTransform parent;\nvar instance2 = pool.Rent(new Vector3(1f, 2f, 3f), Quaternion.identity, parent);\n\n// Use Return() to return the object\npool.Return(instance1);\npool.Return(instance2);\n\n// Dispose() to destroy the pool and all GameObjects\npool.Dispose();\n```\n\nGameObject instances are activated when retrieved from the pool and deactivated when returned.\n\n## Creating Custom Object Pools\n\nYou can create your custom object pool by inheriting from `ObjectPoolBase\u003cT\u003e`.\n\n```cs\nclass PooledObject { }\n\npublic sealed class CustomObjectPool : ObjectPoolBase\u003cPooledObject\u003e\n{\n    protected override PooledObject CreateInstance()\n    {\n        return new PooledObject();\n    }\n\n    protected override void OnDestroy(PooledObject instance)\n    {\n        // Add actions when the object is destroyed in Clear or Dispose\n    }\n\n    protected override void OnRent(PooledObject instance)\n    {\n        // Add actions when rented\n    }\n\n    protected override void OnReturn(PooledObject instance)\n    {\n        // Add actions when returned\n    }\n}\n```\n\nAdditionally, an interface `IObjectPool\u003cT\u003e` is provided, which allows you to implement your own object pool by implementing it.\n\n## Callbacks\n\nYou can insert custom actions on Rent and Return by implementing `IPoolCallbackReceiver`.\n\n```cs\npublic class CallbackExample : MonoBehaviour, IPoolCallbackReceiver\n{\n    public void OnRent()\n    {\n        Debug.Log(\"Rented\");\n    }\n\n    public void OnReturn()\n    {\n        Debug.Log(\"Returned\");\n    }\n}\n```\n\nIn the case of `GameObjectPool` or `SharedGameObjectPool`, this component will be retrieved from the object and its child objects, and the callbacks will be invoked accordingly. For other object pools like `ObjectPool\u003cT\u003e` or pools that inherit from `ObjectPoolBase\u003cT\u003e`, the callbacks are invoked for objects that implement `IPoolCallbackReceiver`.\n\nIf you create your own object pool by implementing `IObjectPool\u003cT`, you will need to handle the `IPoolCallbackReceiver` calls yourself. Implement the necessary logic to invoke these callbacks as needed.\n\n## UniTask\n\nuPools supports asynchronous object pooling using UniTask. When you add UniTask to your project, you can use `AsyncObjectPool\u003cT\u003e`, `AsyncObjectPoolBase\u003cT\u003e`, and `IAsyncObjectPool\u003cT\u003e` for asynchronous object pooling. These pools provide asynchronous versions of Rent, Prewarm, and CreateInstance while behaving like regular `ObjectPool\u003cT\u003e` in other aspects.\n\n## Addressables\n\nWhen using Addressables to generate GameObjects, you need to manage the resources of the loaded Prefabs. uPools offers `AddressableGameObjectPool` for this purpose, which can be used similarly to `GameObjectPool`.\n\n```cs\n// Address of the Prefab\nvar key = \"Address\";\nvar pool = new AddressableGameObjectPool(key);\n\n// Usage is the same as GameObjectPool\nvar instance1 = pool.Rent();\nvar instance2 = pool.Rent(new Vector3(1f, 2f, 3f), Quaternion.identity);\n\npool.Return(instance1);\npool.Return(instance2);\n\npool.Dispose();\n```\n\nYou can also use the asynchronous version `AsyncAddressableGameObjectPool` by introducing UniTask.\n\n## License\n\n[MIT License](LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fannulusgames%2Fupools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fannulusgames%2Fupools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fannulusgames%2Fupools/lists"}