AP_Pool
The script attached to individual pools.
Public Variables
poolBlock : PoolBlock
This is a wrapper containing the object pool fields. Using this wrapper allows multi-editing of object pools in the inspector.
Public Class PoolBlock
prefab : GameObject
The prefab that this pool contains.
size : int
The starting size of the object pool.
emptyBehavior : AP_enum.EmptyBehavior enum { Grow, Fail, ReuseOldest }
How the pool behaves when the pool is empty and a spawn is requested.
Grow: Will instantiate a new object in the pool if the pool is less than maxSize. This will be slowest if the pool has to grow by many items, but it is the most flexible.
Fail: No spawn will be created at this time. Best for performance, but the least flexible.
ReuseOldest: Will find the oldest active object, and reuse it as a new spawn. Useful for certain applications, but can be quite slow with large pool sizes, as it has to check every item to find the oldest one. If the pool is empty only occasionally, consider using Grow, or starting with a larger pool.
maxSize : int
The maximum size to which EmptyBehavior.Grow can enlarge the pool.
This field is hidden when EmptyBehavior.Grow is not selected.
maxEmptyBehavior : AP_enum.MaxEmptyBehavior enum { Fail, ReuseOldest }
How the pool behaves when the pool is at maxSize, is empty, and a spawn is requested.
This field is hidden when EmptyBehavior.Grow is not selected.
Fail: No spawn will be created at this time. Best for performance, but the least flexible.
ReuseOldest: Will find the oldest active object, and reuse it as a new spawn. Useful for certain applications, but can be quite slow with large pool sizes, as it has to check every item to find the oldest one. If the pools is empty only occasionally, consider using Grow, or starting with a larger pool.
printLogOnQuit : bool
When exiting the player, prints a pool usage summary in the console for development and debugging.
Start Size: Size of pool when beginning the scene.
Init Added: Number of objects added by InitializeSpawn() calls at runtime.
Grow Objects: Number of objects added with EmptyBehavior.Grow.
End Size: Total objects of this pool, active and inactive, at the time of the log report.
Failed Spawns: Number of Spawn() requests that didn't return a spawn.
Reused Objects: Number of times an object was reused before despawning normally.
Most objects active at once: The most items for this pool active at once.
Inspector Buttons
Some tools for development and debugging.
Print Log
Prints the current usage log to the console.
Spawn
Request a spawn from this pool.
Public Methods
Normally, you would call the spawn method using MF_AutoPool.Spawn(). However, you can also access a specific pool directly using the following methods:
Spawn : GameObject ( )
Spawn : GameObject ( child : int? )
Spawn : GameObject ( pos : Vector3, rot : Quaternion )
Spawn : GameObject ( child : int?, pos : Vector3, rot : Quaternion )
Spawns an object from this pool at pos position and rot rotation.
if pos and rot are unused, the position and rotation will be that of the pool object.
Optionally, a child index can be specified for prefabs containing children. That child will be enabled, and the others will remain disabled. This feature can be used to simulate different types of objects.
Hidden Variables
pool : Stack { PoolItem }
Items in the pool available for spawning.
masterPool : List { PoolItem }
Used to track all items belonging to the pool, both active and inactive.
Public Class PoolItem
obj : GameObject
The root object of a pool item.
refScript : AP_Reference
A cached reference to the AP_Reference script on obj.
The script attached to individual pools.
Public Variables
poolBlock : PoolBlock
This is a wrapper containing the object pool fields. Using this wrapper allows multi-editing of object pools in the inspector.
Public Class PoolBlock
prefab : GameObject
The prefab that this pool contains.
size : int
The starting size of the object pool.
emptyBehavior : AP_enum.EmptyBehavior enum { Grow, Fail, ReuseOldest }
How the pool behaves when the pool is empty and a spawn is requested.
Grow: Will instantiate a new object in the pool if the pool is less than maxSize. This will be slowest if the pool has to grow by many items, but it is the most flexible.
Fail: No spawn will be created at this time. Best for performance, but the least flexible.
ReuseOldest: Will find the oldest active object, and reuse it as a new spawn. Useful for certain applications, but can be quite slow with large pool sizes, as it has to check every item to find the oldest one. If the pool is empty only occasionally, consider using Grow, or starting with a larger pool.
maxSize : int
The maximum size to which EmptyBehavior.Grow can enlarge the pool.
This field is hidden when EmptyBehavior.Grow is not selected.
maxEmptyBehavior : AP_enum.MaxEmptyBehavior enum { Fail, ReuseOldest }
How the pool behaves when the pool is at maxSize, is empty, and a spawn is requested.
This field is hidden when EmptyBehavior.Grow is not selected.
Fail: No spawn will be created at this time. Best for performance, but the least flexible.
ReuseOldest: Will find the oldest active object, and reuse it as a new spawn. Useful for certain applications, but can be quite slow with large pool sizes, as it has to check every item to find the oldest one. If the pools is empty only occasionally, consider using Grow, or starting with a larger pool.
printLogOnQuit : bool
When exiting the player, prints a pool usage summary in the console for development and debugging.
Start Size: Size of pool when beginning the scene.
Init Added: Number of objects added by InitializeSpawn() calls at runtime.
Grow Objects: Number of objects added with EmptyBehavior.Grow.
End Size: Total objects of this pool, active and inactive, at the time of the log report.
Failed Spawns: Number of Spawn() requests that didn't return a spawn.
Reused Objects: Number of times an object was reused before despawning normally.
Most objects active at once: The most items for this pool active at once.
Inspector Buttons
Some tools for development and debugging.
Print Log
Prints the current usage log to the console.
Spawn
Request a spawn from this pool.
Public Methods
Normally, you would call the spawn method using MF_AutoPool.Spawn(). However, you can also access a specific pool directly using the following methods:
Spawn : GameObject ( )
Spawn : GameObject ( child : int? )
Spawn : GameObject ( pos : Vector3, rot : Quaternion )
Spawn : GameObject ( child : int?, pos : Vector3, rot : Quaternion )
Spawns an object from this pool at pos position and rot rotation.
if pos and rot are unused, the position and rotation will be that of the pool object.
Optionally, a child index can be specified for prefabs containing children. That child will be enabled, and the others will remain disabled. This feature can be used to simulate different types of objects.
Hidden Variables
pool : Stack { PoolItem }
Items in the pool available for spawning.
masterPool : List { PoolItem }
Used to track all items belonging to the pool, both active and inactive.
Public Class PoolItem
obj : GameObject
The root object of a pool item.
refScript : AP_Reference
A cached reference to the AP_Reference script on obj.