menu_bookDocumentation
TemporaryEffect: Auto-Cleanup for Particle and Sound Prefabs
The TemporaryEffect component in s&box is added to prefabs containing ParticleEffects and Sounds. It automatically deletes the GameObject after all particles are gone and sounds are finished playing.
It uses the ITemporaryEffect interface to check if all child effects are done. When they are, the GameObject self-destructs. You can implement ITemporaryEffect on your own components to make them compatible with this auto-cleanup system.
This is commonly used for:
- Explosion prefabs (particles + sound that clean up after playing)
- Impact effects (bullet holes with particle bursts)
- One-shot audio with visual effects
- Any spawned effect that should exist only for its duration
Without TemporaryEffect, spawned effect prefabs would accumulate in the scene indefinitely, causing memory leaks and performance degradation over time.
Was this helpful?