Dogan Kirnaz
  • Welcome
  • Setup
    • Quickstart
  • Basics
    • Agent Extensions
    • Audio Extensions
    • Camera Extensions
    • Collision Extensions
    • Coroutine Extensions
    • Encryption Extensions
    • Format Extensions
    • Game Extensions
    • Json Extensions
    • List Extensions
    • Loop Extensions
    • Material Extensions
    • Math Extensions
    • GameObject Extensions
    • Physics Extensions
    • Object Pool Extensions
    • Scene Extensions
    • PlayerPrefs Extensions
  • Support
    • Support
Powered by GitBook
On this page
  1. Basics

Object Pool Extensions

Create Pool

This method creates a pool of GameObjects based on a specified prefab and pool size, initializing each instance as inactive.

List<GameObject> objectPool = new List<GameObject>(); 

objectPool.CreatePool(prefab, 10);

Resize Pool

This method adjusts the size of an existing pool. If the pool has fewer objects than the new size, it adds more objects. If the pool has more than the new size, it removes the extras.

List<GameObject> objectPool = new List<GameObject>(); 

objectPool.ResizePool(prefab, 20);

Clear Pool

This method clears the pool by destroying all instances and emptying the list.

List<GameObject> objectPool = new List<GameObject>(); 

objectPool.ClearPool();

Get Object

This method retrieves the first inactive object from the pool and activates it for use. If no inactive objects are available, it creates a new one, adds it to the pool, and returns it.

List<GameObject> objectPool = new List<GameObject>(); 

GameObject pooledObject = objectPool.GetObject();

Return Object

This method returns an object back to the pool, resetting its transform and deactivating it so it can be reused later.

List<GameObject> objectPool = new List<GameObject>(); 

objectPool.ReturnObject(pooledObject);
PreviousPhysics ExtensionsNextScene Extensions

Last updated 23 days ago