/unity-dev:unity-audiofrom unity-dev
Diagnoses and fixes Unity audio issues: memory, first-play hitches, codecs, AudioMixer routing, silent or one-ear 3D sound. Covers import settings, DSP buffers, and automation.
Ships in unity-dev. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Audio is the cheapest large win in a Unity project and the easiest to make worse. Almost every number here trades memory or CPU against something inaudible — and the two most common defaults (Decompress On Load on music, a stereo clip on a 3D source) are not trade-offs at all, they are wrong.
| Symptom | Go to |
|---|---|
| Audio memory too high | §1 load type, §2 sample rate (reference/sample-rate-and-codec.md) |
| Hitch the first time a sound plays | §1 — a Streaming clip without background loading |
| Long level-load stall | §1 — music set to Decompress On Load |
| A 3D sound plays in one ear only | §3 — this is a bug, not a setting |
| Everything is silent, or 3D positioning is wrong everywhere | §3 — count the AudioListeners first |
| A Streaming clip is silent the first time it plays | §1 — background loading has not finished |
| Which mixer group does this sound belong in | reference/mixer-routing.md |
| Dozens of Audio Sources route to Master | reference/mixer-routing.md |
| CPU cost does not drop when everything is muted | §4 |
| Latency / crackle | §4 DSP buffer |
| New audio files keep importing on the defaults | reference/import-automation.md |
-executeMethod aborts with "Scripts have compiler errors" after audio work | The contract above, then reference/import-automation.md |
| Effects made in code; no game sound may carry energy above a cutoff (e.g. 16 kHz); a loop clicks at its seam | reference/synth-and-band-limits.md, scripts/spectrum_check.py |
| Music freezes mid-fade while paused, frozen at half volume, or a playlist goes silent for good after focus loss | §5 |
| Folder-wide import settings; routing every AudioSource to its mixer group | reference/import-automation.md, reference/mixer-routing.md |
| What to report after a change | Report format |
Report, then wait. Changing import settings triggers a reimport: it is slow, it rewrites
.metafiles across the project, and it is not something to undo casually. Survey the assets, present what you would change with before/after values, and wait for confirmation before applying anything.
.meta file. Import settings only take effect through
AudioImporter + SaveAndReimport() — or, for anything that should hold for a whole folder,
through an AssetPostprocessor.OnPreprocessAudio keyed on the filename, so a new file dropped
in tomorrow imports correctly with nobody remembering to do it:
reference/import-automation.md.AudioCompressionFormat is in UnityEngine, not UnityEditor;
and AudioImporter.preloadAudioData is obsolete — error CS0619, which fails the build.
Preload moved into the per-platform AudioImporterSampleSettings.-executeMethod in the project. Editor scripts
compile as one assembly, so that CS0619 aborts every unrelated headless run with Aborting batchmode due to failure: Scripts have compiler errors. If a headless Unity command starts
exiting 1 right after audio work, read the compile errors, not the method you invoked.ai.defaultSampleSettings is a struct copy. Take it into a local, edit it, assign it
back; loadType, compressionFormat, quality, preloadAudioData and sampleRateSetting
live there, while forceToMono and loadInBackground stay on the importer itself.clip.channels and clip.frequency on the imported AudioClip report what happened,
and catch a postprocessor that silently stopped matching the path. An importer setting that did
not take is indistinguishable from one that did until you look.Connecting to the Editor: unity-debug → reference/editor-control.md.
| Clip | Load Type |
|---|---|
| Short SFX, uncompressed size under ~200 KB | Decompress On Load |
| Medium, played occasionally | Compressed In Memory |
| Music, ambient beds, voice-over | Streaming |
Decompress On Load on anything over ~1 MB is the classic memory blow-up. The whole clip sits in memory as PCM. It is also why a level load stalls: the decompression happens up front. And it is the import default — a freshly imported
.wavreadsloadType = DecompressOnLoad. Every clip in a project nobody has audited is on the expensive setting.
Every Streaming clip needs Load In Background on — loadInBackground also defaults to
false. Without it, first play blocks.
And then the first play is silent instead. That is the setting working, not failing: the clip has not finished loading when
Play()is called, so there is nothing to hear and no error. Three mitigations, in the order to try them:
- Preload it.
clip.LoadAudioData()at scene start, before anything asks for it.- Schedule it.
AudioSource.PlayScheduled(AudioSettings.dspTime + lead)gives the async load a window to land in.- Change the load type. A source that must be audible the instant it is asked for belongs on Compressed In Memory rather than on Streaming at all: the clip is already resident, so
Play()has its data immediately and there is no async load to wait on. It decodes on the fly as it plays — a little CPU on every play, in exchange for never missing one.Both
AudioClip.LoadAudioDataandAudioSource.PlayScheduledare present — if a snippet does not compile, it is the qualification, not the API.
defaultSampleSettings.1 (100%) — set it downward per category; dialogue 0.7–0.85.forceToMono halves it again.The table, the worked example and the one exception for long music:
reference/sample-rate-and-codec.md.
spatialBlend == 1on a clip withchannels == 2plays the left channel only. This is not a subtle spatialisation artefact — half the audio is gone.
Fix at import: enable Force To Mono (leave normalize on so the level is preserved) and
reimport. panStereo = 0 is a stopgap that hides it without recovering the missing channel.
AudioListenercount must be exactly one. Zero and the whole game is silent; two or more and Unity uses one of them, so positions are computed against a listener nobody meant. Neither state produces an error, and both look from the inspector exactly like a mixer problem or an import problem.
var ls = UnityEngine.Object.FindObjectsByType<UnityEngine.AudioListener>(
UnityEngine.FindObjectsInactive.Include, UnityEngine.FindObjectsSortMode.None);
return ls.Length + ": " + string.Join(", ",
System.Linq.Enumerable.Select(ls, l => l.gameObject.name + (l.enabled ? "" : " (disabled)")));
Zero → add one to the camera that represents the player's ears. More than one → disable all but the intended one rather than deleting, and say which you kept: the extras are usually on a prefab that ships a camera of its own, so deleting fixes the scene and not the prefab. Run this before any import audit — an audit that ends "audio memory halved" on a project with no listener has measured nothing anyone can hear.
Before measuring anything here: confirm a mixer exists at all, and that the listener count is
one (§3). With no mixer asset in the project, routing and effect cost are not the problem you
are looking at. Inventorying the mixers, classifying every Audio Source and assigning groups —
the whole routing pass, and the hard line between what is public API and what is not — is
reference/mixer-routing.md.
AudioSettings.GetConfiguration() gives dspBufferSize and the actual
output sampleRate, which belongs to the device, not to your clips — e.g. a device reporting
48000 against 44.1 kHz clips resamples every clip at runtime, a cost that is invisible
in the importer.Import settings decide what music costs; these three decide whether it sounds broken. Worked
detail, including the code: reference/music-playback.md.
AudioSources, alternating. One source cannot fade out of itself. ~0.5 s on a screen
change, ~2 s between playlist tracks, and stop the outgoing source once the fade ends.Time.unscaledDeltaTime. A pause menu sets timeScale = 0, and a fade
on scaled time then parks the music at half volume until the player resumes. Pair it with
ignoreListenerPause = true on the music sources if the project uses AudioListener.pause.clip.length - clip.time <= crossfade detects the end of a track — and !isPlaying has to
count as ended too. A source stopped from outside (focus loss) never advances time, so a
playlist waiting only on the remaining-time test stays silent for the rest of the session.
Guard that second branch with "music is enabled", or turning music off restarts it.PickNext(count, last, rng)): the
never-repeat rule is unit-testable in EditMode with no AudioSource and no clips.Never "optimised the audio". For each asset changed:
<asset> loadType: DecompressOnLoad → Streaming sampleRate: 44100 → 22050
memory (reported by importer): 4.2 MB → 0.4 MB
Then say what you did not change and why.
Mixing and sound design decisions, DSP authoring beyond the small synthesis rules in
reference/synth-and-band-limits.md, and middleware (FMOD, Wwise) — those bring
their own memory model and their own import path, and the numbers here do not transfer. Nor does
this skill author mixer structure: creating a mixer or a group, re-parenting a group and
setting a group's volume have no public API, so those stay with the user in the Audio Mixer
window. Routing sources into groups that already exist is fully in scope —
reference/mixer-routing.md draws the line. Adaptive
music structure (cues on bar boundaries, layered stems) is a design job, not an import one: §5
stops at "the next track starts without a seam". The SFX event layer — one cue per game event,
voice caps, cooldowns — is unity-game-feel → reference/sfx-events.md, and a footstep an
animation event asks for goes through it (unity-animation → reference/events-and-windows.md).
Git LFS and .gitattributes setup for the binaries this skill imports is unity-new-project;
this skill only says to check that a new audio extension is covered before the first
commit. Generating music and SFX is comfyui-asset-generation (game-assets plugin).
reference/import-automation.md (opens in a new tab)reference/mixer-routing.md (opens in a new tab)reference/music-playback.md (opens in a new tab)reference/sample-rate-and-codec.md (opens in a new tab)reference/synth-and-band-limits.md (opens in a new tab)scripts/spectrum_check.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
unity-audio, audio-optimization, import-settings, audiomixer
npx claudepluginhub tipoli5890/game-studio --plugin unity-dev51 skills in this plugin
/unity-2d-animationSkeletal 2D characters: PSB rig, bones and weights, sprite swaps, 2D IK (2D Animation package)./unity-2d-controllerMove a 2D character: platformer jump, slopes, coyote time, moving platforms, top-down movement./unity-2d-gridGrid tactics and tile puzzles, hex or square: move range, A* paths, line of sight, turns, undo./unity-2d-level2D level layout as data: Tiled/LDtk import, rooms, endless chunks, seeded levels, jump reachability.