# silentbenjininja/unity-audio-events architecture

> Architecture diagram of the GitHub repository silentbenjininja/unity-audio-events, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/silentbenjininja/unity-audio-events
- Repository: https://github.com/silentbenjininja/unity-audio-events

## Overview

Audio Events for Unity is a decoupled runtime audio system. A game object requests playback or owner cleanup through the static message bus; the scene spawner receives requests, enforces cooldown and concurrency limits, and manages pooled AudioSources. Event assets supply AudioResource and mix settings, including AudioClip or AudioRandomContainer variation. The README also documents source tracking and Unity menu setup. Runtime files are excerpted; the prefab setup link is shown as documented, while no unshown pool internals are inferred.

Main entry points: [`Runtime/MB_AudioSourceSpawner.cs`](https://github.com/silentbenjininja/unity-audio-events/blob/main/Runtime/MB_AudioSourceSpawner.cs) (Pooled Source Spawner), [`Runtime/SO_AudioEvent.cs`](https://github.com/silentbenjininja/unity-audio-events/blob/main/Runtime/SO_AudioEvent.cs) (Audio Event Asset), [`Runtime/AudioEventsMessageBus.cs`](https://github.com/silentbenjininja/unity-audio-events/blob/main/Runtime/AudioEventsMessageBus.cs) (Audio Message Bus), [`Editor/AudioEventsMenuItems.cs`](https://github.com/silentbenjininja/unity-audio-events/blob/main/Editor/AudioEventsMenuItems.cs) (Spawner Menu Item)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Audio Runtime"]
  node_bus["Audio Message Bus"]
  node_spawner["Pooled Source Spawner"]
  node_pool["Audio Source Pool"]
  node_unityaudio["Unity AudioSource"]
end

subgraph group_assets["Event Assets"]
  node_event["Audio Event Asset<br/>[SO_AudioEvent.cs]"]
  node_audioresource["Audio Resource"]
end

subgraph group_setup["Unity Setup"]
  node_editor["Spawner Menu Item"]
  node_prefab["Pooled Source Prefab"]
end

node_gameplay(("Gameplay Caller"))

node_gameplay -->|"requests playback"| node_bus
node_gameplay -->|"requests owner stop"| node_bus
node_bus -->|"dispatches requests"| node_spawner
node_spawner -->|"gets pooled source"| node_pool
node_spawner -->|"applies settings"| node_event
node_event -->|"assigns resource"| node_audioresource
node_event -->|"configures source"| node_unityaudio
node_spawner -->|"positions and plays"| node_unityaudio
node_spawner -->|"stops tracked audio"| node_unityaudio
node_editor -->|"creates component"| node_spawner
node_editor -->|"loads prefab"| node_prefab

click node_bus "https://github.com/silentbenjininja/unity-audio-events/blob/main/Runtime/AudioEventsMessageBus.cs"
click node_spawner "https://github.com/silentbenjininja/unity-audio-events/blob/main/Runtime/MB_AudioSourceSpawner.cs"
click node_pool "https://github.com/silentbenjininja/unity-audio-events/blob/main/Runtime/MB_AudioSourceSpawner.cs"
click node_event "https://github.com/silentbenjininja/unity-audio-events/blob/main/Runtime/SO_AudioEvent.cs"
click node_editor "https://github.com/silentbenjininja/unity-audio-events/blob/main/Editor/AudioEventsMenuItems.cs"
click node_prefab "https://github.com/silentbenjininja/unity-audio-events/blob/main/Prefabs/PooledAudioSource.prefab"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_bus,node_spawner,node_pool,node_unityaudio toneBlue
class node_event,node_audioresource toneAmber
class node_editor,node_prefab toneMint
class node_gameplay toneIndigo
```

## Components

### Audio Runtime

- [Audio Message Bus](https://github.com/silentbenjininja/unity-audio-events/blob/main/Runtime/AudioEventsMessageBus.cs): `Runtime/AudioEventsMessageBus.cs`
- [Pooled Source Spawner](https://github.com/silentbenjininja/unity-audio-events/blob/main/Runtime/MB_AudioSourceSpawner.cs): `Runtime/MB_AudioSourceSpawner.cs`
- [Audio Source Pool](https://github.com/silentbenjininja/unity-audio-events/blob/main/Runtime/MB_AudioSourceSpawner.cs): `Runtime/MB_AudioSourceSpawner.cs`
- **Unity AudioSource**

### Event Assets

- [Audio Event Asset](https://github.com/silentbenjininja/unity-audio-events/blob/main/Runtime/SO_AudioEvent.cs): `Runtime/SO_AudioEvent.cs`
- **Audio Resource**

### Unity Setup

- [Spawner Menu Item](https://github.com/silentbenjininja/unity-audio-events/blob/main/Editor/AudioEventsMenuItems.cs): `Editor/AudioEventsMenuItems.cs`
- [Pooled Source Prefab](https://github.com/silentbenjininja/unity-audio-events/blob/main/Prefabs/PooledAudioSource.prefab): `Prefabs/PooledAudioSource.prefab`

### Other components

- **Gameplay Caller**

## Connections

- Gameplay Caller → Audio Message Bus: requests playback (evidence: `README.md`)
- Gameplay Caller → Audio Message Bus: requests owner stop (evidence: `README.md`)
- Audio Message Bus → Pooled Source Spawner: dispatches requests (evidence: `Runtime/MB_AudioSourceSpawner.cs`)
- Pooled Source Spawner → Audio Source Pool: gets pooled source (evidence: `Runtime/MB_AudioSourceSpawner.cs`)
- Pooled Source Spawner → Audio Event Asset: applies settings (evidence: `Runtime/MB_AudioSourceSpawner.cs`)
- Audio Event Asset → Audio Resource: assigns resource (evidence: `Runtime/SO_AudioEvent.cs`)
- Audio Event Asset → Unity AudioSource: configures source (evidence: `Runtime/SO_AudioEvent.cs`)
- Pooled Source Spawner → Unity AudioSource: positions and plays (evidence: `Runtime/MB_AudioSourceSpawner.cs`)
- Pooled Source Spawner → Unity AudioSource: stops tracked audio (evidence: `Runtime/MB_AudioSourceSpawner.cs`)
- Spawner Menu Item → Pooled Source Spawner: creates component (evidence: `Editor/AudioEventsMenuItems.cs`)
- Spawner Menu Item → Pooled Source Prefab: loads prefab (evidence: `Editor/AudioEventsMenuItems.cs`)
