UGTK / Toolkit / Utility Systems / VFX System Completed
VFX Spawner
Summary
The VFX Spawner spawns pooled visual effects (Particle Systems and VFX Graph) through a single Play API supporting three modes: Once, SelfRestartOnEnd and IntervalSpawn. Non-looping effects auto-return to the pool, with an optional parenting policy that detaches the instance and copies the active parent's world transform.
Content
Modules Dependencies
- Utility Systems / Pooling System: instances are taken from and returned to a
Mn_Pooler, which decides the default active parent.
Carried inside the prefabs. These modules are not referenced by the assembly definition - the components are simply already attached to the prefabs this module ships. Remove one of them from the project and the prefab keeps its layout and loses that behaviour, with nothing in the console to say so.
| Module | Component, and the prefab carrying it |
|---|---|
UtilitySystems/PoolingSystem |
Mn_Pooler (in VFXSpawner) |
Setup
- Add the
VFXSpawnerprefab and register your effects in it.VFXLibraryresolves them by name, so the calling code never holds a prefab reference. - Choose a
VFXLoopModeper effect: one that ends by itself, or one that runs until stopped. - Spawn from code or from a UnityEvent.
Mn_VFXAutoReturnsends the instance back to the pool when it finishes, which is what keeps a spawner from allocating a new object per hit.
Mn_VFXHierarchyDeferredRunner handles a case Unity forces on you: an effect asked for during
OnDisable or while a scene is unloading cannot be parented immediately, so it is deferred to the
next safe moment instead of being lost. You do not add it yourself.
An effect that never ends never returns to the pool. A looping VFXLoopMode with no stop is the
usual reason a scene accumulates particle systems until the frame rate falls; if you choose looping,
own the stop.
How To Use
- Add
Mn_VFXSpawnerto a GameObject and assign thepooler(Mn_Pooler) that holds the VFX prefab instances. - Configure
spawnAsChildOfActiveParent(keep as child vs detach + copy world TRS),respectLooping,fallbackLifetimeSeconds,spawnIntervalandburstCount. - Trigger effects from code with
Play(VFXLoopMode.Once | SelfRestartOnEnd | IntervalSpawn, interval)orSpawnOne(), and stop withStop()/StopAllLoopingAndDespawn(). - From UnityEvents/UI buttons use the parameterless wrappers:
PlayOnce,PlaySelfRestartOnEnd,StartSpawningLoop,StopSpawningLoop,SpawnOneEvent,SpawnOneSelfRestartEvent,StopAllLoopingAndDespawnEvent. - On spawn the spawner clears and plays every
ParticleSystemand, via reflection, everyVisualEffectin the instance.
Testing Scene
Open VFXSceneTest in the module's Debug/ folder.
What to do, in order:
- Press PlayOnce() and watch the effect return to the pool when it ends.
- Press PlaySelfRestartOnEnd(), then Stop().
- Switch to interval mode with a short interval and a burst count above one.
- Spawn more effects than the pool holds.
Step 4 is the one to watch: when the pool runs dry the spawner either stops silently or starts recycling effects that are still visible, and both look like a bug in the effect rather than in the pool size. Also try a looping VFX with Respect Looping off — that is how an effect ends up living forever.
VFXSceneTest: three presses of Activate, three bursts. Each instance is taken from the pool
and returned by Mn_VFXAutoReturn when it finishes, so pressing repeatedly does not allocate a
new object each time.
Technical Info
- Mn_VFXSpawner: pool-based spawner with the unified
PlayAPI, interval loop coroutine, parenting policy and PS/VFX Graph start/stop. - VFXLoopMode: enum with
Once,SelfRestartOnEnd,IntervalSpawn. - Mn_VFXAutoReturn: attaches to a spawned instance to return it to the pool at the end of life (respecting looping / fallback lifetime) and optionally trigger self-restart.
- Mn_VFXHierarchyDeferredRunner / VFXLibrary: hierarchy-deferred execution helper and VFX collection utilities.
- Mn_VFXSpawner_Editor: custom inspector.
© 2026 Marcello De Bonis. All rights reserved
Depends on 1
Used by 0
- No other module depends on it.
Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 3 modules in total.
UGTKengine within an engine


