Changing a volume for this session
SetMixerVolume changes how loud one of the game’s volume channels is, until the game puts the player’s own volumes back.
Sounds volume channels
Call SetMixerVolume with your mod id, a channel name and a value in decibels to change that channel for this session. The volumes the player saved are not changed.
public static class Sounds
{
public static bool SetMixerVolume(string modId, string group, float decibels);
}
| Method | Returns | What it does |
|---|---|---|
SetMixerVolume(modId, group, decibels) | bool | Sets a channel’s loudness. Returns false when it was not set. |
Things to know
groupmust beMaster,Sound,MusicorNasty. These are the game’s own volume channels. SettingSoundalso sets the other sound effects channel, the same as the game’s Sound slider does. (Soundalso sets the mixer parameterOtherSounds.)decibelsmust be a real number from -80 (silent) to 0 (loudest). The framework does not compare it with the game’s sliders.modIdis your mod’s id. It has 1 to 64 letters, digits,.,_or-. See Mod id.- The change lasts for the session only. It does not change the volumes the player saved, so
MasterVolume,SfxVolumeandMusicVolumekeep reporting the saved numbers.
Limits
- The game puts the player’s volumes back whenever it sets up its options, so set your value again after a scene change if it has to last. That also happens when the pause menu builds its options page. (The game restores the saved mix when
OptionsController.StartandOptionsMenu.Startrun, because they callVolumeSave.GetVolume, and when the pause menu sets up the options menu.) - It returns
falsewhen nothing was changed. That happens for an invalid mod id, an unknown group, a value out of range, a save loading or saving, or a missing game volume setting. A wrong mod id, group or value is also written to the log once.