Object poolers
Reuse tracers, particles, shells and trajectory renderers.
Create an empty Tracer Pooler GameObject and add ObjectPooler. Assign Objects/Bullet Tracer/Tracer.prefab to Pooled Object.
| Field | Purpose |
|---|---|
| Pooled Object | Prefab to instantiate. |
| Pooled Amount | Initial number of instances; default is 20. |
| Will Grow | Instantiate another object if all current instances are active. |
| Hide Flags | Control whether pooled instances appear in the Hierarchy. |
The current implementation creates its initial pool in Start, not Awake. Request objects after initialization, normally in response to gameplay events. GetPooledObject() returns an available object; position and activate it yourself. A disabled instance becomes available again.
When growth is disabled and every object is in use, the method returns null. Check that result in your own listeners. The supplied tracer, trajectory and particle consumers expect an object, so keep growth enabled or size their pools for the maximum simultaneous use.
Use separate pools for impact particles, muzzle flashes, shell objects and LineRenderers. The supplied effect prefabs use timed deactivation so they can return to the pool. Reuse or add ObjectDeactivator when making your own effects.
GameObject effect = pool.GetPooledObject();
if (effect != null)
{
effect.transform.SetPositionAndRotation(position, rotation);
effect.SetActive(true);
}