Recipes
Audio sound effects music and positional feedback
The game needs to be heard: a coin chime, a footstep, a hit thud, looping ambience, or background music.
AudioEmitterComponent is the one audio primitive; scripts trigger and control it.engine v1.0.234since component-field-contract ecs.component-field-contract.v1, audio.v1, script-semantic-patch-ops.v1Copy for LLM
Use this for
sound effects on events; positional 3D audio from entities; background music; footsteps, pickups, hit sounds, ambience
Not for
visual particles (use ParticleEmitterComponent); UI-only feedback with no sound (see ui-hud-panels-and-widgets)
Pairs with: Combat damage health and respawn scripting, Collectibles pickups scoring and win condition, Atmosphere sky lighting fog and time of day
The recipe
- Attach
AudioEmitterComponentto the sounding entity withproject_add_component(project.entity.component.set):{ "type":"AudioEmitterComponent", "soundAssetId": <audio asset id>, "volume": 1, "pitch": 1, "loop": false, "spatial": true, "rolloff":"inverse", "refDistance": 1, "maxDistance": 32, "playOnStart": false, "enabled": true }. - Positional vs global:
spatial: truemakes the sound attenuate with distance (rolloffislinear,inverse, orexponential;refDistanceandmaxDistanceshape falloff).spatial: falseis a flat UI/music sound. - Play on spawn with
playOnStart: true(looping ambience), or trigger from a script. In a GessaScript body (replaceScriptFromGessaScript) callctx.audio.play(one-shot on this entity),ctx.audio.playSpatial(at a world point),ctx.audio.setBackgroundMusic(the music bed),ctx.audio.setVolume, andctx.audio.stop. - Event-driven SFX: give a pickup or hazard its emitter, and fire
ctx.audio.playfrom the trigger/action handler that already runs the gameplay effect (see collectibles-and-scoring, combat-damage-and-respawn). - Target another entity's emitter with
targetEntityIdwhen one controller should sound off a different source.
Pitfalls
soundAssetIdis optional in the schema but nothing plays without it; set a real audio asset id (prefer the catalog first, see asset-acquisition-strategy).volumeis 0..1,pitchandrefDistance/maxDistanceare> 0(min 0.01); values outside the range fail validation.- The default
enabledisfalseandplayOnStartisfalse; set both true for ambient loops that should start on their own. - Audio is not the renderer: a silent emitter is usually a missing asset or a worker-host audio gap, not a render issue. Confirm the asset id resolves.
- There is no
AudioListenerComponentto attach; it is a roadmap name, not a shipped component.
Verify
engine_get_component_schemaonAudioEmitterComponentfor therolloffenum and numeric bounds.simulation_run(qa.run.start) to confirm the emitter triggers on the intended event.