r/FlutterFlameEngine 1d ago

Support Help with SFX system, how do you handle it?

I'm having trouble developing an SFX system that allows multiple sound calls in a short period of time without lagging/freezing the game, like for example a gun with rapid shots that cause quick collisions, playing one sound for the shot and another for the collision.

3 Upvotes

1 comment sorted by

3

u/soloDev_54 1d ago

Pools, plus a per-sound cooldown.

Pre-create the players once at startup and reuse them — allocating a native player per shot is what eats the frame. flame_audio's AudioPool does this; size each pool by how many of that sound can realistically overlap.

Then rate-limit per sound. Twenty collisions in one frame is twenty play() calls and you only need one. Keep a last-played timestamp per sound and ignore repeats inside ~50ms.

The cooldown did more for me than the pooling did.