{"id":14960997,"url":"https://github.com/gilzoide/unity-prefab-pool","last_synced_at":"2025-10-24T20:30:43.424Z","repository":{"id":168050969,"uuid":"643670919","full_name":"gilzoide/unity-prefab-pool","owner":"gilzoide","description":"Prefab instance pool that is configurable in the Inspector, supports any engine Object type and is available as a serializable C# class, MonoBehaviour and ScriptableObject","archived":false,"fork":false,"pushed_at":"2024-11-30T14:51:06.000Z","size":157,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-31T03:54:02.336Z","etag":null,"topics":["object-pool","object-pooling","package","plugin","prefab","unity","unity3d","upm-package"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gilzoide.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"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},"funding":{"github":["gilzoide"],"patreon":null,"open_collective":null,"ko_fi":"gilzoide","tidelift":null,"community_bridge":null,"liberapay":"gilzoide","issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2023-05-21T22:15:20.000Z","updated_at":"2025-01-06T20:21:17.000Z","dependencies_parsed_at":"2023-11-13T14:30:21.614Z","dependency_job_id":"a87f90d0-e480-4f2e-8bd9-2d22e79625e3","html_url":"https://github.com/gilzoide/unity-prefab-pool","commit_stats":{"total_commits":61,"total_committers":1,"mean_commits":61.0,"dds":0.0,"last_synced_commit":"8f365acbcdd337396b53fe6bbe268605edd79483"},"previous_names":["gilzoide/unity-prefab-pool"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Funity-prefab-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Funity-prefab-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Funity-prefab-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Funity-prefab-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gilzoide","download_url":"https://codeload.github.com/gilzoide/unity-prefab-pool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238030288,"owners_count":19404859,"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","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":["object-pool","object-pooling","package","plugin","prefab","unity","unity3d","upm-package"],"created_at":"2024-09-24T13:23:36.972Z","updated_at":"2025-10-24T20:30:37.984Z","avatar_url":"https://github.com/gilzoide.png","language":"C#","funding_links":["https://github.com/sponsors/gilzoide","https://ko-fi.com/gilzoide","https://liberapay.com/gilzoide"],"categories":[],"sub_categories":[],"readme":"# Prefab Pool\n[![openupm](https://img.shields.io/npm/v/com.gilzoide.prefab-pool?label=openupm\u0026registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.gilzoide.prefab-pool/)\n\nPrefab instance pool that is configurable in the Inspector, supports any engine `Object` type and is available as a serializable C# class, MonoBehaviour and ScriptableObject.\n\n\n## Features\n- Prefab pools may live either as project assets ([PrefabPoolAsset](Runtime/PrefabPoolAsset.cs)), standalone components in the scene ([PrefabPoolComponent](Runtime/PrefabPoolComponent.cs)), or may be a part of your own scripts ([PrefabPool](Runtime/PrefabPool.cs)), whichever fits best your use case.\n- Supports prewarming instances: configure pools to instantiate a number of prefabs when created, with an optional limit of objects per frame to avoid spikes in CPU usage.\n- Supports generic typing for customizing which prefabs can be assigned to the pool.\n  By default, the `GameObject` type is used in the non-generic prefab pool classes.\n- Optionally add scripts that implement [IPooledObject](Runtime/IPooledObject.cs) to the prefab for receiving callbacks when object is taken from/returned to pool.\n  With this, you can also easily return the prefab to the pool by calling the `IPooledObject.ReturnToPool()` extension method.\n- Debug panel in inspector that shows all active and inactive pooled instances.\n- [Addressables](https://docs.unity3d.com/Packages/com.unity.addressables@latest) support: just use the `AddressablePrefabPool*` variants instead of the `PrefabPool*` ones and setup the prefab's asset reference in the Inspector.\n  Addressables are automatically loaded when the first instance is created and released when the pool is disposed of.\n\n\n## How to install\nEither:\n- Use the [openupm registry](https://openupm.com/) and install this package using the [openupm-cli](https://github.com/openupm/openupm-cli):\n  ```\n  openupm add com.gilzoide.prefab-pool\n  ```\n- Install using the [Unity Package Manager](https://docs.unity3d.com/Manual/upm-ui-giturl.html) with the following URL:\n  ```\n  https://github.com/gilzoide/unity-prefab-pool.git#1.0.0\n  ```\n- Clone this repository or download a snapshot of it directly inside your project's `Assets` or `Packages` folder.\n\n\n## Usage example\n```cs\nusing System.Collections;\nusing Gilzoide.PrefabPool;\nusing UnityEngine;\n\npublic class MyScript : MonoBehaviour\n{\n    // 1) Reference a prefab pool:\n\n    // 1.a) Reference for a PrefabPoolComponent from your scene.\n    //      Set this in the Inspector.\n    public PrefabPoolComponent myPoolComponent;\n    \n    // 1.b) Reference for a PrefabPoolAsset from your project.\n    //      Set this in the Inspector.\n    public PrefabPoolAsset myPoolAsset;\n    \n    // 1.c) Private/embedded PrefabPool, needs manual prewarm/disposal.\n    //      Configure it in the Inspector.\n    public PrefabPool myPoolVariable;\n\n\n    void Start()\n    {\n        // 2) (optional) Prewarm private/embedded pools.\n        //    Passing \"instancesPerFrame: N\" makes instances be\n        //    created frame by frame, avoiding CPU spikes.\n        myPoolVariable.Prewarm(10, instancesPerFrame: 1);\n        //    Component/asset pools prewarm automatically in their `OnEnable`.\n\n        for (int i = 0; i \u003c 10; i++)\n        {\n            StartCoroutine(UseInstanceFromPool(myPoolComponent));\n            StartCoroutine(UseInstanceFromPool(myPoolAsset));\n            StartCoroutine(UseInstanceFromPool(myPoolVariable));\n        }\n    }\n\n    // 3) Use the pool:\n    //    (All prefab pool types implement IPrefabPool\u003c\u003e)\n    public IEnumerator UseInstanceFromPool(IPrefabPool\u003cGameObject\u003e pool)\n    {\n        // 3.1) Get an instance.\n        GameObject instance = pool.Get();\n        \n        // 3.2) Do something with your instance.\n        yield return new WaitForSeconds(1);\n        \n        // 3.3) Return instance to pool after done with it.\n        pool.Release(instance);\n    }\n\n    // 4) Dispose of private/embedded pools.\n    //    Embedded pools should always be disposed when not needed anymore!\n    //    Component/asset pools dispose automatically in their `OnDisable`.\n    void OnDestroy()\n    {\n        myPoolVariable.Dispose();\n    }\n}\n```\n\n\n## Using generic prefab pools\n\u003cdetails\u003e\n\u003csummary\u003eSpecifying the prefab type for \u003ccode\u003ePrefabPool\u003c\u003e\u003c/code\u003e\u003c/summary\u003e\n\nTo customize the prefab type accepted by a prefab pool, just declare your variable with a concrete version of the \u003ccode\u003ePrefabPool\u003c\u003e\u003c/code\u003e class.\n\n```cs\nusing Gilzoide.PrefabPool;\nusing UnityEngine;\n\npublic class MyScript : MonoBehaviour\n{\n    public PrefabPool\u003cTransform\u003e myTransformPool;\n\n    void OnDestroy()\n    {\n        myTransformPool.Dispose();\n    }\n}\n```\n![Inspector showing \"myTransformPool\" expecting an object of type \"Transform\"](Extras~/generic-transform-pool.png)\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eSpecifying the prefab type for \u003ccode\u003ePrefabPoolComponent\u003c\u003e\u003c/code\u003e\u003c/summary\u003e\n\nTo customize the prefab type accepted by a prefab pool component, create a concrete class that inherits \u003ccode\u003ePrefabPoolComponent\u003c\u003e\u003c/code\u003e:\n\n```cs\nusing Gilzoide.PrefabPool;\n\npublic class MyScriptPoolComponent : PrefabPoolComponent\u003cMyScript\u003e\n{\n}\n```\n![Inspector showing a prefab pool component expecting a prefab of type \"MyScript\"](Extras~/generic-pool-component.png)\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eSpecifying the prefab type for \u003ccode\u003ePrefabPoolAsset\u003c\u003e\u003c/code\u003e\u003c/summary\u003e\n\nTo customize the prefab type accepted by a prefab pool asset, create a concrete class that inherits \u003ccode\u003ePrefabPoolAsset\u003c\u003e\u003c/code\u003e:\n\n```cs\nusing Gilzoide.PrefabPool;\nusing UnityEngine;\n\n[CreateAssetMenu(menuName = \"MyScriptPoolAsset\")]\npublic class MyScriptPoolAsset : PrefabPoolAsset\u003cMyScript\u003e\n{\n}\n```\n![Inspector showing a prefab pool asset expecting a prefab of type \"MyScript\"](Extras~/generic-pool-asset.png)\n\u003c/details\u003e\n\n\n## Similar projects\n- https://github.com/BeauPrime/BeauPools\n- https://github.com/coimbrastudios/object-pool\n- https://github.com/jeffbert/Unity-Component-Pool\n- https://github.com/expressobits/Pools\n- https://github.com/FredericRP/ObjectPool\n- https://github.com/coryleach/UnityPooling\n- https://github.com/LeGustaVinho/pool\n- https://github.com/QFSW/MasterObjectPooler2\n\n\n## Why another implementation?\nThe reason I made a brand new implementation is because alternatives either:\n- Use singleton/static pools without explicit lifetimes\n- Don't support specifying generic prefab types, accepting only `GameObject`s\n- Don't have Inspector-ready serializable pool types, being too code oriented\n- Don't support pools as assets using `ScriptableObject`s\n- Don't support asynchronous prewarming with configurable batch size, potentially leading to CPU spikes while instantiating prefabs\n- Don't support Addressable asset references","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilzoide%2Funity-prefab-pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgilzoide%2Funity-prefab-pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilzoide%2Funity-prefab-pool/lists"}