
optimize-audio
Optimizes audio memory, CPU cost, and playback quality through import settings and mixer configuration. Use when asked to reduce audio memory or Audio Mixer CPU cost, change clip Load Types, sample rates or codecs, or force 3D audio to mono.
- Installs
- 47
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/unity-technologies/unity-agent-plugin --skill optimize-audio- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads optimize-audio automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Critical Rules
- Do not make changes before reporting findings to the user
- Follow steps in strict order; never jump ahead
- STOP at every
WAITcheckpoint and await the user's response before continuing - Quality is more important than speed: measure before and after every change
- Always verify results in a device build; Editor audio stats are indicative only
0. Set up the execution path
Every 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:
- You need
script evalin 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. - Do not hand-edit
.metafiles to change import settings. Importer values only take effect throughSaveAndReimport()in a live Editor, so an unreachable Editor is a stop, not a cue to edit metadata directly.
Run C# with unity command script eval --caller plugin --skill optimize-audio --code '<snippet>'. Discover the parameter shape from
unity command --format json rather than assuming one. unity command defaults to a 30 second
timeout.
Passing C# to script eval
script eval compiles a statement block, not a file. Two consequences, both of which cause a compile
error rather than a warning:
- No
usingdirectives. The compiler readsusing UnityEngine;as a resource-disposal statement and rejects it (CS0210). - Types must be fully qualified. A bare
AssetDatabaseorAudioImporterdoes not resolve (CS0246/CS0103), and a bareObjectis ambiguous withobject(CS0104).
The recipes in resources/audio-import-api.md are written
fully qualified so they can be passed to script eval as-is.
1. Pre-Flight: Detect Audio System
Before doing anything else, establish the audio environment:
- Detect platform and sample rate: Use
script evalto readEditorUserBuildSettings.activeBuildTargetandAudioSettings.outputSampleRate. The output sample rate affects whether overriding clip sample rates will actually save memory. - Detect AudioMixer presence: Use the mixer-asset query recipe in resources/audio-import-api.md to see if a mixer graph exists. If none exists, note that routing and effect costs are not a concern.
- Detect AudioListener: Use the scene-component query recipe in resources/audio-import-api.md for
UnityEngine.AudioListenerto confirm exactly one listener is present. Multiple listeners produce incorrect spatialization; zero listeners produce silence. - Proceed only after platform and listener state are confirmed.
2. Assess Current State
Before recommending any change, gather observable data:
- Find all AudioSources: Use the scene-component query recipe in resources/audio-import-api.md for
UnityEngine.AudioSource. For each result, use onescript evalcall to batch-read properties — see the batch read recipe in resources/audio-import-api.md. - Inspect mixer topology: If a mixer was found in Pre-Flight, use
script evalto read the AudioMixer's exposed parameters and group count. A group count above ~8 or effects on the Master group are immediate flags. - Check DSP buffer size: Use the DSP buffer recipe in resources/audio-import-api.md to read buffer size. See DSP Buffer Size Guidelines in resources/platform-settings.md for recommended values.
- Report findings before making changes: Summarize ALL detected sources, the listener count, and mixer depth to the user. Flag any immediate risks (e.g., stereo clip with
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.
3. Understand Request
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?"
4. Primary Diagnostic Workflow
Use the findings from Section 2 to determine which sub-section applies. More than one may apply simultaneously.
4A. Force To Mono and Spatial Settings
For any AudioSource where spatialBlend > 0 (3D positioned sound):
- Check clip channel count: Use
script evalto readaudioSource.clip.channels. Ifchannels == 2andspatialBlend == 1, only the left channel plays — this is a bug, not a feature. - Recommend Force To Mono: Use the read importer recipe in resources/audio-import-api.md to inspect current settings, then apply Force To Mono using the force-to-mono recipe.
- Apply and reimport: Report before/after channel counts to the user.
- Verify spatial blend: Use
script evalto confirmaudioSource.spatialBlendis1.0(full 3D) andaudioSource.rolloffModeis set to an appropriate curve.
4B. AudioMixer Audit
-
Measure group depth: Use
script evalto 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
script evalto query each group's effects list. Effects such asAudioReverbFilterrun 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:
- Remove or bypass effects on groups that have no active sources.
- Use snapshots to switch mix states (combat / explore / pause) rather than toggling effects at runtime.
- Flatten unnecessary sub-buses; redirect sources to a shallower ancestor.
WAIT for the user to approve the mixer changes before applying.
-
Verify DSP buffer size: If
bufferLengthfrom Pre-Flight is very small (< 256), recommend increasing it — see DSP Buffer Size Guidelines in resources/platform-settings.md.
4C. Compression Quality Tuning
- Read current compression format: Use the read importer recipe in resources/audio-import-api.md to read
compressionFormatandqualityfor the clips reported by the user. - Apply the platform matrix: See the Compression Format Matrix in resources/platform-settings.md for per-platform recommendations.
- Warn about lossy sources: Use the lossy source check recipe in resources/audio-import-api.md. If the original file is MP3, warn the user that lossy source quality is lost permanently after Unity re-encodes. Recommend WAV or AIFF sources.
4D. Mobile Sample Rate Override
- Identify SFX clips on mobile target: Use the scene-component query recipe for
UnityEngine.AudioSourceand filter for non-music, non-dialogue clips. - Read current sample rate setting: Use the read importer recipe in resources/audio-import-api.md to read
sampleRateSettingandsampleRateOverridefor each clip. - Apply mobile override: Use the sample rate override recipe in resources/audio-import-api.md. See Sample Rate Recommendations in resources/platform-settings.md for per-use-case rates.
- Report savings: Halving the sample rate halves the PCM memory cost. Report the estimated saving for each clip changed.
4E. Load Type and Streaming
- Audit Load Type per clip: Use
script evalto readclip.loadTypefor each clip found in Section 2. - Apply the decision rule: See Load Type Decision Table in resources/platform-settings.md.
- Flag mismatches: See Load Type Mismatch Flags in resources/platform-settings.md. Report both types of mismatches to the user.
- Apply
Load In Backgroundfor any Streaming clip — use the Load In Background recipe in resources/audio-import-api.md.
5. Validation
After any import setting or mixer change:
- Re-read clip stats: Use
script evalto re-readclip.loadType,clip.channels,AudioSettings.outputSampleRate, and the importer'scompressionFormatto confirm the change applied after reimport. - Confirm AudioSource routing: Use the scene-component query recipe for
UnityEngine.AudioSourceand verifyaudioSource.outputAudioMixerGroupis assigned as expected after any mixer restructure. - Report delta: State the before and after values for each setting changed. Do not assume the change was effective without reading back the applied importer values.
- Iterate limit: Maximum 3 adjust-and-verify cycles before pausing to ask the user for feedback.
6. Troubleshooting
Stereo clip on a 3D AudioSource — only left channel audible
- Confirm
audioSource.spatialBlend == 1. - Confirm
audioSource.clip.channels == 2. - Enable
forceToMonoin the AudioClip importer and reimport. Unity mixes both channels to mono during import, preserving level withnormalize = true(keep on). - If the user does not want to reimport: set
audioSource.panStereo = 0as a runtime workaround, but warn this does not recover stereo information.
Decompress On Load clip causes memory spike
- Confirm
clip.loadType == AudioClipLoadType.DecompressOnLoadandclip.lengthis long (> 5 s). - Switch to
Streamingif it is music or ambience,CompressedInMemoryif played only occasionally. - If the clip is short but still large: check
clip.channels(stereo wastes double the memory) andclip.frequency(high sample rate on a mobile target wastes memory). Apply Force To Mono and/or sample rate override.
AudioMixer CPU spike — DSP thread hot
- Confirm with the mixer-asset query recipe that the mixer graph exists.
- Use
script evalto list all groups and their attached effects. Look for reverb, chorus, or EQ on high-level groups. - Move expensive effects down to leaf groups that are only active when sources are playing.
- Use snapshots to bypass effect chains during gameplay states where they are not heard (e.g., bypass reverb during a menu).
- If the DSP buffer is small (64 or 128 samples), raise it — see DSP Buffer Size Guidelines in resources/platform-settings.md.
Vorbis quality artifacts on dialogue
- Confirm
defaultSampleSettings.compressionFormat == AudioCompressionFormat.Vorbis. - Confirm
defaultSampleSettings.quality— default is 0.5, which is often audible on voice. Raise to 0.7–0.85. - On iOS: switch to AAC instead of Vorbis (hardware decode, better quality at equivalent bitrate).
- Confirm the source file is lossless (WAV or AIFF). MP3 sources cannot recover quality lost before Unity's re-encode.
AudioListener count is not exactly one
- Zero listeners: All audio will be silent. Use
script evalto add anAudioListenercomponent to the main camera:UnityEngine.Camera.main.gameObject.AddComponent<UnityEngine.AudioListener>(). - Multiple listeners: Unity uses the last enabled one, producing unpredictable spatialization. Use the scene-component query recipe for
UnityEngine.AudioListenerand disable all but the intended one.
Load In Background causes first-play silence
This is expected behavior: the clip has not finished loading when Play() is first called. Mitigate with:
- Preload the clip at scene start by calling
clip.LoadAudioData()before it is needed. - Use
AudioSource.PlayScheduled()with a slight delay to allow async load to complete. - For AudioSources that must play immediately: switch to
CompressedInMemory(synchronous on first play) rather thanStreamingwith background load.
7. Completion
After finishing the audit or optimization:
- Summarize every setting changed with before/after values.
- List any clips or groups that still need attention (e.g., clips that require on-device measurement to confirm savings).
- If the user needs runtime memory measurement, point them at the Memory Profiler package, which reports the largest AudioClips by runtime byte cost.
- If mixer CPU is still high after the audit, point them at the Unity Profiler's Audio module for DSP thread profiling.
Detailed References
- Platform settings, compression matrix, load types, sample rates: resources/platform-settings.md
- AudioImporter API recipes and code patterns: resources/audio-import-api.md
See Also
- Memory Profiler package — finds the largest AudioClips by runtime byte cost.
- Unity Profiler, Audio module — DSP CPU markers and frame-time budget.
audio-setup-mixers— creating mixers and routing Audio Sources into groups.
FAQ
What does the optimize-audio skill do?
Optimizes audio memory, CPU cost, and playback quality through import settings and mixer configuration. Use when asked to reduce audio memory or Audio Mixer CPU cost, change clip Load Types, sample rates or codecs, or force 3D audio to mono.
How do I install optimize-audio?
Run npx skills add https://github.com/unity-technologies/unity-agent-plugin --skill optimize-audio in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/optimize-audio/ (personal) or .claude/skills/optimize-audio/ (project).
Which AI agents can use optimize-audio?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is optimize-audio safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains optimize-audio?
It is published by unity-technologies in unity-technologies/unity-agent-plugin. It has 47 recorded installs.
More from unity-technologies/unity-agent-plugin
unity-cli
unity-technologies/unity-agent-plugin
Controls the Unity Editor and projects from the command line, driving a running Editor to edit scenes and assets or run C. Use when asked to install or manage Editors, licenses, or projects, set up version control, build, test, configure the Unity MCP server, or run any unity command.
urp-postprocessing
unity-technologies/unity-agent-plugin
Sets up, configures, and debugs URP post-processing with the Volume framework. Use for bloom, tonemapping, color adjustments, depth of field, vignette, or other Volume overrides.
ui-ugui
unity-technologies/unity-agent-plugin
Understands, edits, and generates Unity uGUI Canvas hierarchies, RectTransforms, Layout Groups, and prefab UI. Use for requests involving Canvas, uGUI, RectTransform, or prefab UI files.
unity-package-management
unity-technologies/unity-agent-plugin
Adds, removes, upgrades, and discovers Unity (UPM) packages from outside the Editor, with the Pipeline package commands first and a C script as the fallback. Use for package installs, verifying package IDs and versions, or choosing which packages a game needs.
ui-uitk
unity-technologies/unity-agent-plugin
Open the skill to read its SKILL.md instructions.
localization
unity-technologies/unity-agent-plugin
Sets up and configures Unity Localization, including locales, String and Asset Tables, and CJK fonts. Use when the user asks to add languages, translate UI text, or mentions i18n or multilingual support.
Popular media & creative skills
hyperframes
heygen-com/hyperframes
Read first to make, edit, animate or render any video with HyperFrames (HTML rendered to video), including launch films, explainers, music videos, charts, maps, vertical clips, title cards, captions and overlays. Holds the render contract, the work loop and what each kind of video needs.
media-use
heygen-com/hyperframes
Get or make any media for a HyperFrames video - music, sound effects, images, icons, logos, voiceover, avatar and generated video, transcripts, cutouts, colour grades and looks - with HeyGen or free local tools, and mix placed audio. Also for footage that looks dark, flat or dull, or should be stylized or hidden.
hyperframes-registry
heygen-com/hyperframes
About 450 ready-made HyperFrames blocks and components installed as editable source - transitions, overlays, titles, kinetic type, captions, charts, map overlays, 3D, camera moves. Use it before hand-building any named visual (CRT scanlines, glitch, film grain, a chart); also for hyperframes add and catalog.
hyperframes-creative
heygen-com/hyperframes
Non-animation creative direction for HyperFrames videos. Use for design spec (frame.md / design.md) handling, palettes, typography, narration, beat planning, audio-reactive visuals, composition patterns, and brand / style decisions. For atomic motion patterns and scene blueprints, use hyperframes-animation.
ai-video-generation
101-skills/superpowers
Generate AI videos with Google Veo, Seedance 2.0, HappyHorse, Wan, Grok and 40+ models via inference.sh CLI. Models: Veo 3.1, Veo 3, Seedance 2.0, HappyHorse 1.0, Wan 2.5, Grok Imagine Video, OmniHuman, Fabric, HunyuanVideo. Capabilities: text-to-video, image-to-video, reference-to-video, video editing, lipsync, avatar animation, video upscaling, foley sound. Use for: social media videos, marketing content, explainer videos, product demos, AI avatars. Triggers: video generation, ai video, text to video, image to video, veo, animate image, video from image, ai animation, video generator, generate video, t2v, i2v, ai video maker, create video with ai, runway alternative, pika alternative, sora alternative, kling alternative, seedance, happyhorse
ai-image-generation
101-skills/superpowers
Generate AI images with GPT-Image-2, FLUX, Gemini, Grok, Seedream, Reve and 50+ models via inference.sh CLI. Models: GPT-Image-2, FLUX Dev LoRA, FLUX.2 Klein LoRA, Gemini 3 Pro Image, Grok Imagine, Seedream 4.5, Reve, ImagineArt. Capabilities: text-to-image, image-to-image, inpainting, LoRA, image editing, upscaling, text rendering. Use for: AI art, product mockups, concept art, social media graphics, marketing visuals, illustrations. Triggers: flux, image generation, ai image, text to image, stable diffusion, generate image, ai art, midjourney alternative, dall-e alternative, text2img, t2i, image generator, ai picture, create image with ai, generative ai, ai illustration, grok image, gemini image, gpt image, openai image, chatgpt image