npx skills add ...
npx skills add unity-technologies/skills --skill optimize-audio
Optimizes Unity 6 audio memory, CPU cost, and playback quality through correct import settings and mixer configuration. Use when the user wants to reduce audio memory usage, choose the right Load Type for short clips versus music versus ambient beds, configure platform-appropriate sample rates and codecs, force 3D audio to mono, or reduce AudioMixer CPU cost from deep group trees or effects running on silent paths.
npx skills add unity-technologies/skills --skill optimize-audio
WAIT checkpoint and await the user's response before continuingEvery C# step below runs inside a live Editor through the Unity CLI. The unity-cli skill owns
getting you there — installing the CLI, confirming a connected Editor, adding the project's
com.unity.pipeline package, telling a genuinely absent Editor apart from one stuck in Safe Mode,
and discovering the Editor's command catalog. Follow it first; don't re-derive any of it here.
Two things it can't know for you:
eval in particular, not just a reachable Editor. Confirm it appears in the
catalog. Its presence depends on the Pipeline package version, not on the CLI, so a healthy
install can still lack it — if it's missing, say so and stop..meta files to change import settings. Importer values only take effect
through SaveAndReimport() in a live Editor, so an unreachable Editor is a stop, not a cue to
edit metadata directly.Run C# with unity command eval --code '<snippet>'. Discover the parameter shape from
unity command --format json rather than assuming one. unity command defaults to a 30 second
timeout.
evaleval compiles a statement block, not a file. Two consequences, both of which cause a compile
error rather than a warning:
using directives. The compiler reads using UnityEngine; as a resource-disposal
statement and rejects it (CS0210).AssetDatabase or AudioImporter does not resolve
(CS0246 / CS0103), and a bare Object is ambiguous with object (CS0104).The recipes in resources/audio-import-api.md are written
fully qualified so they can be passed to eval as-is.
Before doing anything else, establish the audio environment:
eval to read EditorUserBuildSettings.activeBuildTarget and AudioSettings.outputSampleRate. The output sample rate affects whether overriding clip sample rates will actually save memory.UnityEngine.AudioListener to confirm exactly one listener is present. Multiple listeners produce incorrect spatialization; zero listeners produce silence.Before recommending any change, gather observable data:
UnityEngine.AudioSource. For each result, use one eval call to batch-read properties — see the batch read recipe in resources/audio-import-api.md.eval to read the AudioMixer's exposed parameters and group count. A group count above ~8 or effects on the Master group are immediate flags.spatialBlend = 1, Decompress On Load on a clip > 1 MB, reverb on the Master group).WAIT for the user to review the assessment before proceeding.
Route to the correct section based on what the user needs:
| User Says | Path |
|---|---|
| "audio memory too high" / "memory profiler shows audio" | Section 4 — Import settings audit |
| "load times slow" / "decompression stall" | Section 4 — Load Type review |
| "DSP spike" / "mixer CPU" / "audio CPU high" | Section 4B — Mixer audit |
| "3D sound wrong" / "only left channel plays" / "stereo in 3D" | Section 4A — Force To Mono + spatial settings |
| "quality artifacts" / "voice sounds bad" / "Vorbis crackling" | Section 4C — Compression quality tuning |
| "mobile audio battery" / "mobile memory" | Section 4D — Mobile sample rate override |
| "set import settings on all clips" / "batch audio settings" | Section 4 — Bulk import audit |
| "streaming" / "background loading" / "Addressables audio" | Section 4E — Streaming and async load |
If the symptom is ambiguous, ask: "Is the problem audio memory usage, DSP CPU spikes, or audio playback quality?"
Use the findings from Section 2 to determine which sub-section applies. More than one may apply simultaneously.
For any AudioSource where spatialBlend > 0 (3D positioned sound):
eval to read audioSource.clip.channels. If channels == 2 and spatialBlend == 1, only the left channel plays — this is a bug, not a feature.eval to confirm audioSource.spatialBlend is 1.0 (full 3D) and audioSource.rolloffMode is set to an appropriate curve.Measure group depth: Use eval to walk the mixer's group tree and count levels. More than 3 levels (Master → SFX / Music / Voice → sub-bus) adds routing overhead every frame, even when children are silent.
Check effects on silent groups: Use eval to query each group's effects list. Effects such as AudioReverbFilter run their DSP at full cost even when no AudioSource routes to that group.
Flag SFX Reverb on parent groups: This is the most expensive built-in effect. If found on the Master or a high-level group, flag it explicitly.
Present recommendations to the user:
WAIT for the user to approve the mixer changes before applying.
Verify DSP buffer size: If bufferLength from Pre-Flight is very small (< 256), recommend increasing it — see DSP Buffer Size Guidelines in resources/platform-settings.md.
compressionFormat and quality for the clips reported by the user.UnityEngine.AudioSource and filter for non-music, non-dialogue clips.sampleRateSetting and sampleRateOverride for each clip.eval to read clip.loadType for each clip found in Section 2.Load In Background for any Streaming clip — use the Load In Background recipe in resources/audio-import-api.md.After any import setting or mixer change:
eval to re-read clip.loadType, clip.channels, AudioSettings.outputSampleRate, and the importer's compressionFormat to confirm the change applied after reimport.UnityEngine.AudioSource and verify audioSource.outputAudioMixerGroup is assigned as expected after any mixer restructure.audioSource.spatialBlend == 1.audioSource.clip.channels == 2.forceToMono in the AudioClip importer and reimport. Unity mixes both channels to mono during import, preserving level with normalize = true (keep on).audioSource.panStereo = 0 as a runtime workaround, but warn this does not recover stereo information.clip.loadType == AudioClipLoadType.DecompressOnLoad and clip.length is long (> 5 s).Streaming if it is music or ambience, CompressedInMemory if played only occasionally.clip.channels (stereo wastes double the memory) and clip.frequency (high sample rate on a mobile target wastes memory). Apply Force To Mono and/or sample rate override.eval to list all groups and their attached effects. Look for reverb, chorus, or EQ on high-level groups.defaultSampleSettings.compressionFormat == AudioCompressionFormat.Vorbis.defaultSampleSettings.quality — default is 0.5, which is often audible on voice. Raise to 0.7–0.85.eval to add an AudioListener component to the main camera: UnityEngine.Camera.main.gameObject.AddComponent<UnityEngine.AudioListener>().UnityEngine.AudioListener and disable all but the intended one.Load In Background causes first-play silenceThis is expected behavior: the clip has not finished loading when Play() is first called. Mitigate with:
clip.LoadAudioData() before it is needed.AudioSource.PlayScheduled() with a slight delay to allow async load to complete.CompressedInMemory (synchronous on first play) rather than Streaming with background load.After finishing the audit or optimization:
audio-setup-mixers — creating mixers and routing Audio Sources into groups.