Show / Hide Table of Contents

Class ObjectPool

A pool that can be used to store old instances of objects when not in use, and can be renabled if needed.

This is done to reduce the amount of calls to GameObject.Instantiate and GameObject.Destroy

NOTE: Every object used through this pool must have a PoolableObject component attached

Inheritance
object
Object
Component
Behaviour
MonoBehaviour
ObjectPool
Namespace: WeaverCore
Assembly: WeaverCore.dll
Syntax
public sealed class ObjectPool : MonoBehaviour

Fields

| Edit this page View Source

MultiThreaded

Can the pool work with multiple threads?

Declaration
public static readonly bool MultiThreaded
Field Value
Type Description
bool
| Edit this page View Source

ResetComponents

Should the pool reset all components on an object to a clean slate when returned back to the pool?

Declaration
public bool ResetComponents
Field Value
Type Description
bool
| Edit this page View Source

ResetPositions

Should the pool reset the transform data on an object back to a clean slate when returned back to the pool?

Declaration
public bool ResetPositions
Field Value
Type Description
bool

Properties

| Edit this page View Source

AmountInPool

Declaration
public int AmountInPool { get; }
Property Value
Type Description
int
| Edit this page View Source

Prefab

The prefab this pool is instantiating

Declaration
public PoolableObject Prefab { get; set; }
Property Value
Type Description
PoolableObject

Methods

| Edit this page View Source

ClearPool()

Clears the pool of all it's stored objects

Declaration
public void ClearPool()
| Edit this page View Source

Create(Component)

Creates a new pool for a prefab

Declaration
public static ObjectPool Create(Component prefab)
Parameters
Type Name Description
Component prefab

The prefab the pool will be instantiating

Returns
Type Description
ObjectPool

Returns a new pool for the prefab

Exceptions
Type Condition
Exception

Throws if the prefab is null

| Edit this page View Source

Create(GameObject)

Creates a new pool for a prefab

Declaration
public static ObjectPool Create(GameObject prefab)
Parameters
Type Name Description
GameObject prefab

The prefab the pool will be instantiating

Returns
Type Description
ObjectPool

Returns a new pool for the prefab

Exceptions
Type Condition
Exception

Throws if the prefab is null

| Edit this page View Source

Create(PoolableObject)

Creates a new pool for a prefab

Declaration
public static ObjectPool Create(PoolableObject prefab)
Parameters
Type Name Description
PoolableObject prefab

The prefab the pool will be instantiating

Returns
Type Description
ObjectPool

Returns a new pool for the prefab

| Edit this page View Source

FillPool(int)

Fills the pool with a certain amount of objects

Declaration
public void FillPool(int amount)
Parameters
Type Name Description
int amount

The amount to fill the pool with

| Edit this page View Source

FillPoolAsync(int)

Fills the pool with a certain amount of objects. This function will add 1 object to the pool each frame to stagger instantiations

Declaration
public void FillPoolAsync(int amount)
Parameters
Type Name Description
int amount

The amount to fill the pool with

| Edit this page View Source

Instantiate()

Instantiates a new object from the pool

Declaration
public GameObject Instantiate()
Returns
Type Description
GameObject

The new object instance

| Edit this page View Source

Instantiate(Transform)

Instantiates a new object from the pool

Declaration
public GameObject Instantiate(Transform parent)
Parameters
Type Name Description
Transform parent

The parent transform of the instantiated object

Returns
Type Description
GameObject

The new object instance

| Edit this page View Source

Instantiate(Transform, bool)

Instantiates a new object from the pool

Declaration
public GameObject Instantiate(Transform parent, bool instantiateInWorldSpace)
Parameters
Type Name Description
Transform parent

The parent transform of the instantiated object

bool instantiateInWorldSpace

Should the object be positioned in world space? If false, it will be positioned relative to the parent

Returns
Type Description
GameObject

The new object instance

| Edit this page View Source

Instantiate(Vector3, Quaternion)

Instantiates a new object from the pool

Declaration
public GameObject Instantiate(Vector3 position, Quaternion rotation)
Parameters
Type Name Description
Vector3 position

The position of the instantiated object

Quaternion rotation

The rotation of the instantiated object

Returns
Type Description
GameObject

The new object instance

| Edit this page View Source

Instantiate(Vector3, Quaternion, Transform)

Instantiates a new object from the pool

Declaration
public GameObject Instantiate(Vector3 position, Quaternion rotation, Transform parent)
Parameters
Type Name Description
Vector3 position

The position of the instantiated object

Quaternion rotation

The rotation of the instantiated object

Transform parent

The parent transform of the instantiated object

Returns
Type Description
GameObject

The new object instance

| Edit this page View Source

Instantiate<T>()

Instantiates a new object from the pool

Declaration
public T Instantiate<T>()
Returns
Type Description
T

The new object instance

Type Parameters
Name Description
T

The component type to get from the instantiated object

| Edit this page View Source

Instantiate<T>(Transform)

Instantiates a new object from the pool

Declaration
public T Instantiate<T>(Transform parent)
Parameters
Type Name Description
Transform parent

The parent transform of the instantiated object

Returns
Type Description
T

The new object instance

Type Parameters
Name Description
T

The component type to get from the instantiated object

| Edit this page View Source

Instantiate<T>(Transform, bool)

Instantiates a new object from the pool

Declaration
public T Instantiate<T>(Transform parent, bool instantiateInWorldSpace)
Parameters
Type Name Description
Transform parent

The parent transform of the instantiated object

bool instantiateInWorldSpace

Should the object be positioned in world space? If false, it will be positioned relative to the parent

Returns
Type Description
T

The new object instance

Type Parameters
Name Description
T

The component type to get from the instantiated object

| Edit this page View Source

Instantiate<T>(Vector3, Quaternion)

Instantiates a new object from the pool

Declaration
public T Instantiate<T>(Vector3 position, Quaternion rotation)
Parameters
Type Name Description
Vector3 position

The position of the instantiated object

Quaternion rotation

The rotation of the instantiated object

Returns
Type Description
T

The new object instance

Type Parameters
Name Description
T

The component type to get from the instantiated object

| Edit this page View Source

Instantiate<T>(Vector3, Quaternion, Transform)

Instantiates a new object from the pool

Declaration
public T Instantiate<T>(Vector3 position, Quaternion rotation, Transform parent)
Parameters
Type Name Description
Vector3 position

The position of the instantiated object

Quaternion rotation

The rotation of the instantiated object

Transform parent

The parent transform of the instantiated object

Returns
Type Description
T

The new object instance

Type Parameters
Name Description
T

The component type to get from the instantiated object

Exceptions
Type Condition
Exception

Throws if the component type T doesn't exist on the instantiated object

| Edit this page View Source

ReturnToPool(GameObject)

Returns an object to the pool

Declaration
public void ReturnToPool(GameObject gameObject)
Parameters
Type Name Description
GameObject gameObject

The object to return

| Edit this page View Source

ReturnToPool(GameObject, float)

Returns an object to the pool

Declaration
public void ReturnToPool(GameObject gameObject, float time)
Parameters
Type Name Description
GameObject gameObject

The object to return

float time

The delay before the object is put back in the pool

Exceptions
Type Condition
Exception

Throws if the returning object doesn't have a PoolableObject component attached

| Edit this page View Source

ReturnToPool(PoolableObject)

Returns an object to the pool

Declaration
public void ReturnToPool(PoolableObject poolableObject)
Parameters
Type Name Description
PoolableObject poolableObject

The object to return

| Edit this page View Source

ReturnToPool(PoolableObject, float)

Returns an object to the pool

Declaration
public void ReturnToPool(PoolableObject poolableObject, float time)
Parameters
Type Name Description
PoolableObject poolableObject

The object to return

float time

The delay before the object is put back in the pool

Exceptions
Type Condition
Exception

Throws if the returning object doesn't have a PoolableObject component attached

| Edit this page View Source

ReturnToPool<T>(T)

Returns an object to the pool

Declaration
public void ReturnToPool<T>(T component) where T : Component
Parameters
Type Name Description
T component

The object to return

Type Parameters
Name Description
T

The type of the component

| Edit this page View Source

ReturnToPool<T>(T, float)

Returns an object back to the pool

Declaration
public void ReturnToPool<T>(T component, float time) where T : Component
Parameters
Type Name Description
T component

The component on the object being returned

float time

A delay before the object is returned to the pool

Type Parameters
Name Description
T

The type of the component

Exceptions
Type Condition
Exception

Throws if the returning object doesn't have a PoolableObject component attached

Extension Methods

ReflectionUtilities.ReflectCallMethod(object, string, object[], BindingFlags)
ReflectionUtilities.ReflectGetField(object, string, BindingFlags)
ReflectionUtilities.ReflectGetMethod(object, string, BindingFlags)
ReflectionUtilities.ReflectGetProperty(object, string, BindingFlags)
ReflectionUtilities.ReflectSetField(object, string, object, BindingFlags)
ReflectionUtilities.ReflectSetProperty(object, string, object, BindingFlags)
CoroutineUtilities.RunCoroutineWhile<T>(T, IEnumerator, Func<bool>)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Generated by DocFX
☀
☾