> For the complete documentation index, see [llms.txt](https://docs.meshmap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.meshmap.com/unity-sdk/building-blocks/audio.md).

# Audio

The **Audio** system provides a centralized way to manage music, sound effects (SFX), and UI sounds.

## Components

### [AudioManager](https://github.com/MeshMap/com.meshmap.sdk.bb/blob/main/Runtime/Audio/AudioManager.cs)

* Singleton manager for playing Music, SFX, UI, and Other `AudioClips`.
* Supports:
  * Mixer group routing (`MusicGroup`, `SFXGroup`, `UIGroup`, `OtherGroup`).
  * Fade-in/out for Music.
  * Saving/restoring music playback positions.
  * Randomized pitch for SFX/UI.
  * Override previous Other audio clip.
* Requires an `AudioRegistry`.asset in a `Resources` folder in your project.

### [AudioRegistry](https://github.com/MeshMap/com.meshmap.sdk.bb/blob/main/Runtime/Audio/AudioRegistry.cs)

* `ScriptableObject` that maps `string` keys to `AudioClips`.
* Create one `AudioRegistry` in your Project via `Create > MeshMapLabs > Building Blocks > Audio > AudioRegistry`. Place it in a `Resources` folder to be loaded via `AudioRegistryCache.Instance`.
* Change load path dynamically with `AudioRegistryCache.SetResourcePath()`.

### [AudioSettings](https://github.com/MeshMap/com.meshmap.sdk.bb/blob/main/Runtime/Audio/AudioSettings.cs)

* UI slider bindings for mixer volume control.
* Saves user preferences to `PlayerPrefs`.
* Mixer parameters: `MusicVolume`, `SFXVolume`, `UIVolume`.

### [PlaySound](https://github.com/MeshMap/com.meshmap.sdk.bb/blob/main/Runtime/Audio/PlaySound.cs)

* Simple `MonoBehaviour` to play a clip on an `AudioSource`.
* Optional pitch randomization.
* Can trigger on `OnEnable` or manually.

## Example Workflow

1. Add the `AudioManagerWithSettings`.prefab to your scene.
2. Create an `AudioRegistry`.asset in a `Resources` folder.
3. Add unique `string` keys and `AudioClips` to the `AudioRegistry`.
4. Add three `Sliders` to your game UI and assign them in `AudioSettings`.
5. Add a `SliderValueText` component to each `Slider` and assign a `TextMeshProUGUI` to each.
6. Play the `AudioClips` from anywhere in your project by referencing `AudioManager.Instance`.

## Example Code

```csharp
// Play UI sound
AudioManager.Instance.PlayUI("UI.ButtonClick", randomizePitch: true);

// Play looping background music
AudioManager.Instance.PlayMusic("Music.MainTheme", loop: true, fadeIn: true);

// Adjust music volume via UI slider
public void OnMusicVolumeChanged(float value)
{
    AudioManager.Instance.SetMusicVolume(value);
}
```

## Prefabs

* **AudioManager** — Ready-to-use manager `GameObject` with mixer groups and `AudioSource`s preconfigured. Make sure there is an [`AudioRegistry`](#audioregistry-and-audioregistrycache) in your Project.
* **AudioManagerWithSettings** — Variant with `AudioSettings` UI bindings. Requires a UI with volume sliders to be setup.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.meshmap.com/unity-sdk/building-blocks/audio.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
