Unity Sound Mixer

Per-category volume settings that drive your Unity Audio Mixer and persist through Game Settings.

What the system is for

Volume sliders in Unity look easy until you wire them up. The audio mixer expects a logarithmic value, your slider is linear, the saved value has to come back from PlayerPrefs and the gameplay code wants to know whether music is muted. Each project ends up rediscovering the same conversion, the same listener pattern and the same set of bugs around startup order.

The Sound Mixer in Serenity wraps a Unity Audio Mixer behind a service-based volume layer. Volumes are exposed through use cases, organized by category, and connected to Game Settings so the player choice survives between sessions.

The Unity problem

A real settings menu needs more than one volume. Master, music, sound effects, voice and ambient are common categories, and each one has to map to a specific exposed parameter on a Unity Audio Mixer. Without an abstraction, every slider hard-codes the parameter name, every slider duplicates the conversion to decibels, and every reload of the settings has to push values back into the mixer manually.

Mixer parameters also bleed into business logic. Asking whether music is currently muted should not require knowing the exposed parameter name. Persisting and restoring volume on game start should not require knowing that the value lives in PlayerPrefs.

How Serenity approaches it

Serenity exposes the mixer through ISoundMixerService with use cases SoundMixerSetVolume and a corresponding get-volume input. Settings are described through ISoundMixerSettings on the Domain side. The Unity implementation, UnitySoundMixerService, maps categories to exposed parameters of a Unity Audio Mixer using UnitySoundMixerSettings and UnityAudioMixerReturn.

The service is registered through a UnitySoundMixerInstaller. Game Settings consumes it to drive per-category persistent volumes, and the settings menu reads and writes through the same service rather than touching the mixer directly.

How it fits into Serenity

The Sound Mixer lives in the Serenity.SoundMixer namespace and follows the foundation's layered structure. Domain entities describe the mixer settings contract. The Application layer exposes the service and use cases. The Infrastructure layer wires Unity Audio Mixer support, including settings editors and the UnitySoundMixerSettings asset.

Sound Mixer connects directly with Game Settings so each volume category has a persistent value. It cooperates with the Audio Player and the Music Player to ensure their categories route through the mixer. The Menu System and Modal System ultimately benefit from the result because their UI sounds inherit the same category volumes.

Practical workflow

  1. Create a Unity Audio Mixer and expose the volume parameters you want to control.
  2. Configure UnitySoundMixerSettings with the category to exposed parameter mapping.
  3. Let the sound mixer installer register the service in the initialization pipeline.
  4. Bind the settings menu sliders to SoundMixerSetVolume per category.
  5. Persist the chosen values through Game Settings so they restore on the next session.
  6. Verify that Audio Player and Music Player playback respects the category volumes.

What you get

  • ISoundMixerService with SoundMixerSetVolume and corresponding get-volume use case
  • Per-category volume model described by ISoundMixerSettings
  • UnitySoundMixerSettings mapping categories to Unity Audio Mixer parameters
  • Editor support through UnitySoundMixerSettingsEditor and UnitySoundMixerServiceEditor
  • Installer that registers the service for the whole project
  • Integration with Game Settings so each volume category is persisted
  • Drives Audio Player and Music Player playback through the same mixer
  • Clean separation between Unity Audio Mixer and the rest of the foundation

When to use this

  • Projects with a settings menu that exposes more than one volume slider.
  • Games that need volume preferences to survive across sessions.
  • Teams that want music and sound effect volumes to actually route through a Unity Audio Mixer.
  • Codebases that need to query, set and persist category volumes without referencing the mixer asset directly.

Related systems

Use Serenity when you want a mixer layer that already cooperates with audio playback, settings persistence and menus, but still lets you control which categories exist and how they map to your Audio Mixer.

Back to the home page