ObjectPoolController Class |

Namespace: (Default Namespace)
Assembly: AudioToolkit (in AudioToolkit.dll) Version: 8.2.0.0 (8.2.0.0)

public static class ObjectPoolController
The ObjectPoolController type exposes the following members.

Name | Description | |
---|---|---|
![]() ![]() | isDuringPreload |

Name | Description | |
---|---|---|
![]() ![]() | Destroy |
Destroys the specified game object, respectively sets the object inactive and adds it to the pool.
|
![]() ![]() | Instantiate(GameObject) |
Retrieves an instance of the specified prefab. Either returns a new instance or it claims an instance
from the pool.
|
![]() ![]() | Instantiate(GameObject, Vector3, Quaternion) |
Retrieves an instance of the specified prefab. Either returns a new instance or it claims an instance
from the pool.
|
![]() ![]() | InstantiateWithoutPool(GameObject) |
Instantiates the specified prefab without using pooling.
from the pool.
|
![]() ![]() | InstantiateWithoutPool(GameObject, Vector3, Quaternion) |
Instantiates the specified prefab without using pooling.
from the pool.
|
![]() ![]() | Preload |
Preloads as many instances to the pool so that there are at least as many as
specified in preloadCount.
|

GameObject.Instantiate(...) calls are relatively time expensive. If objects of the same type are frequently created and destroyed it is good practice to use object pools, particularly on mobile devices. This can greatly reduce the performance impact for object creation and garbage collection.
How does pooling work?
Instead of actually destroying object instances, they are just set inactive and moved to an object "pool". If a new object is requested it can then simply be pulled from the pool, instead of creating a new instance.
Awake(), Start() and OnDestroy() are called if objects are retrieved from or moved to the pool like they were instantiated and destroyed normally.

- Add the PoolableObject script component to the prefab to be pooled. You can set the maximum number of objects to be be stored in the pool from within the inspector.
- Replace all Instantiate( myPrefab ) calls with ObjectPoolController.Instantiate( myPrefab )
- Replace all Destroy( myObjectInstance ) calls with ObjectPoolController.Destroy( myObjectInstance )
- All data must get initialized in the Awake() or Start() function
- OnDestroy() will get called a second time once the object really gets destroyed by Unity
- If a poolable objects gets parented to none-poolable object, the parent must be destroyed using ObjectPoolController.Destroy( ... ) even if it is none-poolable itself.
- If you store a reference to a poolable object then this reference does not evaluate to null after ObjectPoolController.Destroy( ... ) was called like other references to Unity objects normally would. This is because the object still exists - it is just in the pool. To make sure that a stored reference to a poolable object is still valid you must use PoolableReferenceT.
