{"id":23594202,"url":"https://github.com/rodrigoueda/com.rodrigoueda.objectpool","last_synced_at":"2026-05-18T10:33:04.271Z","repository":{"id":268836962,"uuid":"298057917","full_name":"rodrigoueda/com.rodrigoueda.objectpool","owner":"rodrigoueda","description":null,"archived":false,"fork":false,"pushed_at":"2020-09-23T20:29:43.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-22T01:32:52.509Z","etag":null,"topics":["objectpool","objectpool-pattern","package","unity","unity3d"],"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/rodrigoueda.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":"2020-09-23T18:20:40.000Z","updated_at":"2020-09-23T20:29:46.000Z","dependencies_parsed_at":"2024-12-19T07:47:45.101Z","dependency_job_id":"983ff0aa-5f6b-4e52-8026-59b268d95393","html_url":"https://github.com/rodrigoueda/com.rodrigoueda.objectpool","commit_stats":null,"previous_names":["rodrigoueda/com.rodrigoueda.objectpool"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rodrigoueda/com.rodrigoueda.objectpool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigoueda%2Fcom.rodrigoueda.objectpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigoueda%2Fcom.rodrigoueda.objectpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigoueda%2Fcom.rodrigoueda.objectpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigoueda%2Fcom.rodrigoueda.objectpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rodrigoueda","download_url":"https://codeload.github.com/rodrigoueda/com.rodrigoueda.objectpool/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigoueda%2Fcom.rodrigoueda.objectpool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33174714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"ssl_error","status_checked_at":"2026-05-18T09:27:28.300Z","response_time":71,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["objectpool","objectpool-pattern","package","unity","unity3d"],"created_at":"2024-12-27T09:16:08.561Z","updated_at":"2026-05-18T10:33:04.253Z","avatar_url":"https://github.com/rodrigoueda.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unity Object Pool\n\n## Usage\n\n- Use the namespace ``` ObjectPool ```\n- Your new prefab reference needs to be of type ``` PoolableGameObject ``` instead of ``` GameObject ```\n- On your ``` Start ``` method, call the ``` Prewarm() ```function\n\n```C#\nusing UnityEngine;\nusing ObjectPool;\n\npublic class TestObjectPool : MonoBehaviour\n{\n    public PoolableGameObject cubes;\n\n    void Start()\n    {\n        cubes.Prewarm();\n    }\n}\n\n```\n\n- On unity editor, there is additional information to edit:\n\n![PoolableGameObject data](https://gist.githubusercontent.com/rodrigoueda/c6a714d7cbbdc58641b89679e06d5efb/raw/5a93d4db1ace6263f98ab0dd587bd95aa89401e5/PoolableGameObject_Data.png)\n\n- **Prefab**: The GameObject to be pooled\n- **AmountToPool**: How many GameObjects should be instatiated\n- **ShouldExpand**: Should expand the pool when every instantiated objects are already in use?\n- **Disposable**: Should dispose when the pool is soft flushed?\n\n## Retrieving\n\n- Instead of using unity ``` Object.Instantiate ``` static method, switch to ``` ObjectPoolManager.Instance.Retrieve(PooledGameObject) ```\n- ``` PooledGameObject.instance ``` is the now the way to access the created GameObject\n\n```C#\nvoid Update()\n{\n    if (Input.GetKeyUp(KeyCode.Space)) {\n        PooledGameObject gameObj = ObjectPoolManager.Instance.Retrieve(cubes);\n\n        gameObj.instance.transform.parent = this.transform;\n        gameObj.instance.transform.position = Vector3.zero;\n        gameObj.instance.SetActive(true);\n    }\n}\n```\n\n- There is a second optional parameter to the ``` Retrieve ``` function which creates the objects with a delay self recycle\n- This parameter represents the time in seconds\n\n```C#\nvoid Update()\n{\n    if (Input.GetKeyUp(KeyCode.Space)) {\n        PooledGameObject gameObj = ObjectPoolManager.Instance.Retrieve(cubes, 2f);\n\n        gameObj.instance.transform.parent = this.transform;\n        gameObj.instance.transform.position = Vector3.zero;\n        gameObj.instance.SetActive(true);\n    }\n}\n```\n\n## Recycling\n\n- Switch ``` Object.Destroy ``` to ``` ObjectPoolManager.Instance.Recycle(PooledGameObject) ```\n\n```C#\nvoid Update()\n{\n    if (Input.GetKeyUp(KeyCode.Escape)) {\n        ObjectPoolManager.Instance.Recycle(gameObj);\n    }\n}\n```\n\n- Also, it's possible to delay the recycle using a second parameter, the value is in seconds\n\n```C#\nvoid Update()\n{\n    if (Input.GetKeyUp(KeyCode.Escape)) {\n        ObjectPoolManager.Instance.Recycle(gameObj, 1f);\n    }\n}\n```\n\n## Flushing the pool\n\n- Use the method ``` ObjectPoolManager.Instance.DisposePool(); ``` to empty the pool\n- Remember that only the objects marked as Disposable will be destroyed\n- To hard flush the pool, removing every single object, use a boolean parameter ``` ObjectPoolManager.Instance.DisposePool(true); ```\n\n## IPoolable interface\n\n- Optionally, the prefab script can implement IPoolable interface\n- This way, every time it's instance is retrieved or recycled, the methods ``` Retrieve() ``` and ``` Recycle() ``` will be fired respectively.\n\n```C#\nusing UnityEngine;\nusing ObjectPool;\n\npublic class CubeBehaviour : MonoBehaviour, IPoolable\n{\n    public void Retrieve()\n    {\n        print(\"Object Retrieved\");\n    }\n\n    public void Recycle()\n    {\n        print(\"Object Recycled\");\n    }\n}\n```\n\n## Managed Update\n\n- When working with a great amount of objects, it's considered a good practice to center each individual ``` Update() ``` into a single behaviour in order to optimize performance\n- ObjectPoolManager is also able to concentrate instanced objects updates, just extend IManagedUpdate interface\n- It's possible to combine IPoolable and IManagedUpdate interfaces\n\n```C#\nusing UnityEngine;\nusing ObjectPool;\n\npublic class CubeBehaviour : MonoBehaviour, IPoolable, IManagedUpdate\n{\n    public void Retrieve()\n    {\n        ObjectPoolManager.Instance.RegisterManagedUpdate(this);\n    }\n\n    public void Recycle()\n    {\n        ObjectPoolManager.Instance.UnregisterManagedUpdate(this);\n    }\n\n    public void ManagedUpdate(float deltaTime)\n    {\n        print(deltaTime);\n    }\n\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigoueda%2Fcom.rodrigoueda.objectpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frodrigoueda%2Fcom.rodrigoueda.objectpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigoueda%2Fcom.rodrigoueda.objectpool/lists"}