# 3. Particle and VFX Pools
Part of [[Object Pooling and Spawners]]. Back: [[2. Projectile Pools]]. Next: [[4. Enemy Spawners]].
> [!warning] Code not compiled in Unity
> `ParticleFxPool` was type-checked against Unity 6000.5.8f1 (`ParticleSystem.Play`, `Stop`, `ParticleSystemStopBehavior`). It has not been run on a particle prefab. `VisualEffect` pooling was not compiled in this series; Play/Stop/Reinit names come from that Editor's `UnityEngine.VFXModule` XML.
## 3.1 Particles are just GameObjects with leftover state
A pooled burst that is `SetActive(true)` without a fresh `Play` can resume mid-loop or show particles from the last impact. Official 6000.5 `ParticleSystem.Play` "starts the Particle System and resets its playback time to 0." Official `Stop(bool withChildren, ParticleSystemStopBehavior stopBehavior)` accepts `StopEmitting` and `StopEmittingAndClear`. Official `Clear` "removes all particles."
On **Get**: place it, `Play(true)` (with children).
On **Release**: `Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear)`, then deactivate.
Do not `Destroy` the system after every impact. That is the allocation this pool exists to avoid. How to *author* the burst itself stays in [[Particle Systems and Layered Effects]] and [[4.Controlling Particles from Script]].
If the effect is looping (a torch, a shower), either keep it out of this burst pool or Stop/Clear before Release so a later Get does not inherit the loop.
## 3.2 ParticleFxPool
Call `Release` when the system has finished. A one-shot can use `ParticleSystem.main.duration` plus a small margin, or `isPlaying` in a short watcher. This class only exposes `PlayAt` and `Release`; hook the watcher on the prefab if you do not want the spawner to poll.
```csharp
using UnityEngine;
using UnityEngine.Pool;
/// <summary>
/// Pools a ParticleSystem prefab. Official Play() resets playback time to 0.
/// On release, Stop(true, StopEmittingAndClear) removes leftover particles.
/// </summary>
public sealed class ParticleFxPool : MonoBehaviour
{
[SerializeField] ParticleSystem prefab;
[SerializeField] Transform poolRoot;
[SerializeField] int defaultCapacity = 8;
[SerializeField] int maxSize = 32;
[SerializeField] bool collectionCheck = true;
ObjectPool<ParticleSystem> _pool;
void Awake()
{
if (prefab == null)
{
Debug.LogError("ParticleFxPool: assign a ParticleSystem prefab.", this);
return;
}
_pool = new ObjectPool<ParticleSystem>(
createFunc: () =>
{
var fx = Instantiate(prefab, poolRoot);
fx.gameObject.SetActive(false);
return fx;
},
actionOnGet: fx => fx.gameObject.SetActive(true),
actionOnRelease: fx =>
{
fx.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
fx.gameObject.SetActive(false);
if (poolRoot != null)
fx.transform.SetParent(poolRoot, false);
},
actionOnDestroy: fx =>
{
if (fx != null)
Destroy(fx.gameObject);
},
collectionCheck: collectionCheck,
defaultCapacity: defaultCapacity,
maxSize: maxSize);
}
public ParticleSystem PlayAt(Vector3 position, Quaternion rotation)
{
var fx = _pool.Get();
fx.transform.SetPositionAndRotation(position, rotation);
fx.Play(true);
return fx;
}
public void Release(ParticleSystem fx)
{
if (fx == null || _pool == null)
return;
_pool.Release(fx);
}
void OnDestroy()
{
_pool?.Dispose();
_pool = null;
}
}
```
A projectile impact (part 2) can `fxPool.PlayAt(contact.point, Quaternion.LookRotation(contact.normal))` and let a component on the prefab release when `isPlaying` becomes false.
## 3.3 VisualEffect (VFX Graph)
Official `UnityEngine.VFX.VisualEffect` methods in 6000.5.8f1's VFXModule XML:
- `Play()` — "send a play event to every Spawn system."
- `Stop()` — "send a stop event to all Spawn systems."
- `Reinit` is present on the component (used in official remarks as a point after which event name IDs are valid).
A VFX Graph prefab pools the same way as a ParticleSystem: Instantiate once in `createFunc`, `Play()` on Get, `Stop()` on Release, `Destroy` only in `actionOnDestroy`. If a graph keeps internal state across plays (buffers, previous events), call `Reinit` on Get before `Play`, and confirm on *your* graph — that path was **not play-tested** here. Event names and binders stay in [[VFX Graph]] / [[2. VFX Exposed Properties Events and Binders]].
Quest still has a VFX budget ([[6. VFX Graph Performance and Quest]], [[6. Quest Performance Budgets]]). A pool that can hold 32 graphs is not a promise that 32 should play at once; cap the *active* count the same way part 4 caps live enemies.
Next: [[4. Enemy Spawners]].