SFXSingle
Overview
Convenient wrapper around StudioEventEmitter with extra behaviors for play style, attenuation overrides, manual volume, and parameter control. Useful for both one-shot SFX and looping music (with ALWAYS). fileciteturn7file2
Play Formats
enum PlayFormatSingle { SINGLE, MULTIPLE, REPLAY, ALWAYS }
- SINGLE — ignore
Play()if already playing. - MULTIPLE — allow overlapping plays.
- REPLAY — stop and immediately restart.
- ALWAYS — ensure playing whenever the parent Scene is active. fileciteturn7file2
Serialized Settings
- EventReference
FMODEvent - bool
stopOnDisable(defaulttrue) - bool
stopOnDestroy(defaulttrue) - bool
overrideAttenuation(defaulttrue)int minAttenuation(default1),int maxAttenuation(default300),bool drawAttenuationGizmos
- bool
overrideVolume(defaultfalse)- float
Volume[0..1]with runtime updates
- float
- PlayFormatSingle
playFormat(defaultSINGLE) fileciteturn7file2
Odin Inspector attributes (
FoldoutGroup,ShowIf,ButtonGroup, etc.) organize the inspector UI. fileciteturn7file2
Lifecycle
- Awake()
- Adds
StudioEventEmitterif missing. - Applies attenuation overrides to the emitter.
- Sets
emitter.EventReference = FMODEvent. - If
playFormat == ALWAYS, starts playback. - If
overrideVolume, applies initialVolume. fileciteturn7file2
- Adds
- OnEnable() — if
ALWAYS, ensure playing. - OnDisable() —
Stop()whenstopOnDisableis true. - OnDestroy() —
Stop()whenstopOnDestroyis true. fileciteturn7file2
Control API
public void Play();
public void Stop();
public bool IsPlaying();
public void SetPause(bool pause);
public void SetCustomParameter(string param, float value);
public void EnableParameterByName(string param); // sets to 1
public void DisableParameterByName(string param); // sets to 0
public void SetVolume(float value); // 0..1
public float GetVolume();
public void Mute(bool mute);
Play() honors the configured play format; SetVolume() updates the FMOD Event instance volume immediately. fileciteturn7file2
Gizmos
When attenuation overrides are active and gizmos enabled, draws wire spheres at min/max distances to visualize attenuation. fileciteturn7file2