Making instruments

Develop procedural car audio for Unity

Prototype a car sound outside Unity, compile the same Processor for the game, and iterate with automatic native rebuilds and restored scene controls.

By Maru editorial team10 min read
  • unity
  • game-audio
  • processors
  • tutorial

A car sound needs to respond to RPM, throttle, gear changes and the listener's position. Designing that response inside a full game makes each experiment depend on the vehicle controller, scene setup and gameplay state. Designing it in a separate prototype helps, but creates another problem if someone then has to rewrite the sound for Unity.

Maru's Unity integration keeps the sound in one Processor. You develop it in the module workbench, compile it to a native library, and let Unity drive its parameters. A watcher rebuilds source changes and imports each successful revision into the open Unity project. You can work on the sound in isolation, then judge the same model against gameplay inputs.

The example is Engine Synth: three car presets, four camera/listening perspectives and live telemetry controls. This is a development integration tested with Unity 6 on macOS Apple silicon. It requires Maru's native toolkit checkout; the developer walkthrough provides access details, setup commands, C# bindings and the complete procedure.

Why develop the sound outside the game?

Consider an exhaust that becomes too harsh under load. In a game, reaching that moment may require driving to the right location, selecting a vehicle, accelerating and switching cameras. Those changing conditions make it harder to tell whether an audio edit helped.

In the workbench, hold RPM and throttle fixed, select a preset, and change only the exhaust model. Then sweep the inputs deliberately. You can separate an issue in the synthesis from a mistake in the game's telemetry mapping. The module's face gives sound designers controls suited to that experiment; it does not require a playable vehicle or a running game scene.

This also gives a coding agent a smaller problem. A request such as “soften the cabin sound at high RPM while keeping the exterior character” can stay within the Processor and its controls. The vehicle physics and camera system can continue evolving independently. Rendered audio can catch silence or invalid output; listening still decides whether the change sounds right.

Isolation does not remove the need to test in the game. It makes the first comparison repeatable. Unity then answers a different question: does the sound respond correctly to the actual controller, perspective changes and frame-by-frame inputs?

Engine Synth module face with vehicle controls, pedals, exhaust design and listening perspectives
Engine Synth's module face in Maru. Design the engine and its controls in isolation before connecting them to gameplay.

What Unity actually runs

A module owns its Processor, parameter schema and presets. The Processor is the sound-generating code; the schema declares controls, ranges and enum values. For this export, the Maru cross-platform compiler turns the Processor into native code. The exporter links a game C API and generates Unity C# bindings, an Inspector and native-plugin importer settings from the module.

Unity loads that native library. It does not interpret the TypeScript or host a VST3. The browser workbench and native export derive from the same authored Processor, with separate runtime verification. The browser face stays in the workbench; Unity uses its generated Inspector and your game's interface.

The responsibilities are explicit:

PartResponsibility
ModuleCombustion, exhaust, intake, mechanical noise, parameter smoothing and presets
Unity gameplay scriptRead vehicle telemetry and set named controls in physical units
Generated Unity sourceManage the native instance and pass Unity's stereo audio buffers to it
Development watcherCompile changed sources and stage a complete revision for the Editor

Gameplay code sets parameters on the main thread. The audio source uses Unity's OnAudioFilterRead callback to pass an interleaved buffer through the native boundary. Synthesis stays in the compiled Processor. Its realtime processing contract excludes allocation, locks, I/O and JavaScript calls. That contract still needs performance testing in the intended player under game load.

Try the cars and cameras

After preparing the supplied showroom, open its saved scene in Unity, enter Play mode and enable Sound in the on-screen controls.

  1. Choose Hot hatch, hold RPM steady and vary throttle. Then compare V8 muscle and Turbo boxer rally car at the same inputs. Car selection applies module-owned factory presets.
  2. Keep one car selected and switch between Exhaust, Engine bay, Cabin and Pass-by. The demo moves the visual camera and explicitly sets the Processor's listening perspective.
  3. Auto lap starts enabled so the module drives its own engine model. Take over with the pedals, or use fixed telemetry in Tools to compare RPM, throttle, road speed and gear. The full-size showroom cars stay parked.
Unity showroom with a visible car, car presets, camera perspectives and large gas and brake controls
The Unity showroom runs the compiled Processor. Car presets, listening perspectives and pedal inputs make the same sound model easy to compare in a scene.

The showroom's large pedals accept mouse or keyboard input: W/Up for gas, S/Down for brake, 1–3 or keypad keys for the primary cars, and C for cameras. Space starts or stops the curved pedal cycle; adjust its duration and variation below the scene. F1 opens developer controls, including fixed telemetry, repeatable cycle seeds and the full sound parameter set. The factory browser also exposes the module's other named sounds.

Camera position alone does not model a cabin, glass or obstruction. The demo maps a viewpoint to an authored sound perspective. In a driving game, your camera controller makes that selection and your vehicle controller supplies the telemetry. Named controls such as car.rpm and listener.view form the boundary between gameplay and sound; neither side needs to duplicate the other's implementation.

Edit the Processor while Unity stays open

There are two useful kinds of iteration. Parameter changes reach the running native instance without recompiling: changing RPM, selecting a car or moving between perspectives. Source changes alter the sound model itself and require a new native build.

For source iteration, save the scene, stop Play mode for the first watcher installation, and start the Unity development watcher from the toolkit. After that installation, use Play mode normally:

  1. Save a source edit. The watcher follows the Processor and its resolved DSP dependencies using the same source-closure machinery as the workbench. It coalesces rapid edits and supersedes builds made stale by another save.
  2. Build a native revision. Compilation runs in an isolated output folder. A failed build leaves the previous ready revision available.
  3. Publish the complete revision locally. The watcher validates metadata, seals the generated files and library, then atomically advances a ready manifest outside Unity's Assets folder.
  4. Import and resume. An Editor bridge polls that manifest, validates all files, captures supported controls, stops Play, imports the new assets, lets C# recompile, and resumes Play if it was running.

Stable script GUIDs keep scene component references connected. The temporary snapshot restores supported Maru scalar targets and showroom selections on saved scene objects. You can repeat the same comparison without manually copying libraries or resetting every control after each build.

For example, hold the V8 at a fixed RPM in Cabin view, edit its exhaust filtering, save, and compare after Play resumes. For a preset edit, switch to another car and back: restored live controls take precedence over new defaults. A useful agent brief is:

Make the cabin less sharp at this RPM. Keep the vehicle inputs and camera mapping unchanged. Explain the Processor change and what I should compare after the watched rebuild. Check the rendered native audio as well.

Why the update restarts Play mode

Unity keeps native plugins loaded for the Editor session. Overwriting the same library does not mean Unity starts executing the new code. Each development revision therefore has a distinct native library name, and generated bindings point at that name.

This loop includes a short stop, import and restart. Fresh Processor instances reset oscillator phase, notes and effect tails. Arbitrary gameplay state and runtime-spawned objects need their own restoration; the snapshot is not a save-game system. After eight development updates, restart the Editor to release the retained libraries. A native build can succeed while a C# import fails, so inspect Unity's Console as well as the watcher output.

How it compares with other audio workflows

The useful comparison is where you author the sound, how gameplay controls it, and what you have to repeat when the sound model changes. Different approaches solve different parts of that problem:

ApproachWhere it helpsWhat Maru adds for this example
Recorded loops, one-shots and layered samplesPreserve the character of a recorded vehicle; layers and playback controls make recordings respond to a gameA procedural model offers another way to vary engine behavior continuously. You can change its combustion or exhaust model rather than record each variation. Recordings can still provide details the model does not capture
Audio middlewareOrganize, control and tune a game's audio in a dedicated authoring environmentThis example concentrates on writing and iterating on a custom sound generator. It exports a Unity AudioSource; connecting it to middleware would be a separate integration
Synthesis authored in the game engineWork directly with the engine's audio tools and gameplay systemsMaru lets you develop the sound model independently and compile it for the host, with a named parameter boundary between sound and gameplay
Standalone prototype followed by a Unity rewriteExperiment before committing to the game's implementationThe native export carries the authored Processor into Unity, avoiding a second sound implementation to maintain
A manually rebuilt native audio pluginImplement custom DSP with explicit control over the native integrationThe watcher handles source dependencies, staging, import and supported control restoration after a successful build

Independent authoring and live tuning already exist in game audio tools. For example, FMOD's Unity Live Update lets you adjust, mix and profile content while the game runs. Unreal's MetaSound Editor provides graph-based sound creation and preview inside the engine. Maru's specific benefit here is the combination of an isolated, code-authored Processor, generated game bindings and a watched native rebuild loop.

Choose based on the sound and your team's workflow. A recorded engine may be the right foundation when the identity of a real car matters. An engine's own audio tools may suit a project already built around them. Maru is useful when you want to experiment with the sound-generating behavior itself and carry that implementation into gameplay. These are workflow tradeoffs, not measured claims of lower CPU use, smaller downloads or faster iteration than every alternative. The source rebuild also restarts Play mode, as described above.

What game developers gain

  • Work before the vehicle is playable. An audio designer can develop a car's character with controlled RPM and throttle while a programmer works on physics. Agreeing on units and parameter names gives both sides a useful handoff: the game supplies car.rpm; the Processor decides how it sounds.
  • Compare changes under the same conditions. Fixed telemetry, factory presets and repeatable pedal gestures give the team a common audition. A sound change can be compared at the same load and perspective instead of relying on two different driving attempts.
  • Separate vehicle tuning from sound design. A different controller can supply the same parameter contract. Changing an exhaust model or a preset need not require changing the vehicle physics; changing the controller still needs a check that its inputs map correctly to the sound.
  • Give coding agents a focused task. A small Processor and its controls make a concrete brief: change a sound behavior, render it, then compare it in the showroom. The resulting DSP change can be reviewed independently of the scene, camera and vehicle code.

This approach is also worth exploring for electric motors, machinery and invented vehicles: sounds whose behavior should follow a game's systems. Each needs an appropriate sound model and testing in its intended host. The current Unity export supplies a procedural source, while your game's audio setup remains responsible for mixing, routing and spatial behavior.

Build and test the player separately

The watched libraries are Editor-only. When the sound is ready for a player, stop the watcher and replace the development export with a clean static export. The build guard refuses bindings that still point to development revisions. Test the exact platform and scripting backend you intend to ship.

The example's automated checks have exercised the three cars and four perspectives through Unity's mixer, and measured changed native output after a watched rebuild. That establishes the tested integration behavior. Listening, real audio-device deadlines, performance under graphics load and packaged player qualification remain separate checks.

Tell us what your game needs

We are also working on Unreal Engine integration and exploring other game engines. Those integrations are developing separately; the Unity example here documents the path we have tested.

If you are a game developer, write to us. Tell us which engine and version you use, your target platforms, the sound you want to build and the gameplay inputs it should follow. If you already use middleware or have a prototype, include that context too. We will help you work out an approach and try to build something useful for your game.

We are excited about game audio because sound can respond to the behavior of a whole system, from a single motor to a changing environment. Your projects and practical needs can help shape the integrations we build.

Music tools on your computer.

Install and manage Maru and community plugins in one app, and play them in your DAW.

Chicken Synth, a cat keyboard, effects knobs and wavetable and MIDI panels