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). fileciteturn7file2

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. fileciteturn7file2

Serialized Settings

  • EventReference FMODEvent
  • bool stopOnDisable (default true)
  • bool stopOnDestroy (default true)
  • bool overrideAttenuation (default true)
    • int minAttenuation (default 1), int maxAttenuation (default 300), bool drawAttenuationGizmos
  • bool overrideVolume (default false)
    • float Volume [0..1] with runtime updates
  • PlayFormatSingle playFormat (default SINGLE) fileciteturn7file2

Odin Inspector attributes (FoldoutGroup, ShowIf, ButtonGroup, etc.) organize the inspector UI. fileciteturn7file2

Lifecycle

  • Awake()
    • Adds StudioEventEmitter if missing.
    • Applies attenuation overrides to the emitter.
    • Sets emitter.EventReference = FMODEvent.
    • If playFormat == ALWAYS, starts playback.
    • If overrideVolume, applies initial Volume. fileciteturn7file2
  • OnEnable() — if ALWAYS, ensure playing.
  • OnDisable()Stop() when stopOnDisable is true.
  • OnDestroy()Stop() when stopOnDestroy is true. fileciteturn7file2

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. fileciteturn7file2

Gizmos

When attenuation overrides are active and gizmos enabled, draws wire spheres at min/max distances to visualize attenuation. fileciteturn7file2