Skip to content

FMOD And Audio

Use GameAudioService.Shared for new code. It accepts event paths, GUIDs, loose sound files, streaming music files, and snapshots through AudioSource.

using STS2RitsuLib.Audio;
GameAudioService.Shared.PlayOneShot(
AudioSource.Event("event:/MyMod/ui/click"),
new AudioPlaybackOptions
{
Volume = 0.8f,
Parameters = FmodParameterMap.Set(("intensity", 1f)),
Scope = AudioLifecycleScope.Room,
});

For quick compatibility with existing path-based calls, GameFmod.Studio and Sts2SfxAlignedFmod remain available.

Keep the returned handle when you need to stop or adjust playback later.

var loop = GameAudioService.Shared.PlayLoop(
AudioSource.Event("event:/MyMod/ambience/engine"),
new AudioPlaybackOptions
{
Routing = new AudioRoutingOptions(Channel: "my_mod_ambience"),
Scope = AudioLifecycleScope.Run,
});
loop?.TrySetParameter("danger", 0.5f);
loop?.TryStop();

Use PlayMusic(...) for music handles and FollowAdaptiveMusic(...) for room / combat / victory plans.

Load banks before using their events:

FmodStudioDeferredBankRegistration.RegisterBank("res://MyMod/audio/MyMod.bank");
FmodStudioDeferredBankRegistration.RegisterStudioGuidMappings("res://MyMod/audio/guid_map.json");

If a bank is optional, use the lower-level FmodStudioServer.TryLoadBank(...) and handle failure gracefully.

OptionUse
ScopeStops audio automatically with room, combat, run, or manual lifetime.
ScopeTokenGroups handles under a manual scope.
Routing.ChannelAllows one active handle per channel, optionally replacing the old one.
Routing.TagGroups several handles for StopTag(...).
CooldownMsPrevents rapid repeated playback.
UseVanillaRoutingLets one-shot and music event paths route through vanilla where applicable.

Use routing for UI and looping ambience. Avoid global stop calls unless the mod owns all audio in that group.