askvity

How do I add spatial audio in Unity?

Published in Unity Audio 4 mins read

To add spatial audio in Unity, you need to enable spatialization and configure your audio sources. Here’s a step-by-step guide:

Step 1: Enable Spatialization in Unity

  1. Install an appropriate Spatial Audio Plugin: Unity doesn't have built-in spatial audio; you'll need a plugin. Common choices include:

    • Resonance Audio (Google): A free, widely used option. Generally available in older Unity versions.
    • Oculus Spatializer (Meta): Specifically designed for Oculus VR, but can be used in other projects.
    • Steam Audio (Valve): Another popular, free choice, especially strong for complex acoustic environments.
    • Microsoft Spatial Sound Platform: For deploying to Microsoft platforms like Xbox and HoloLens

    Follow the plugin's specific installation instructions. This typically involves importing an asset package into your Unity project.

  2. Set the Audio Settings:

    • Go to Edit > Project Settings > Audio.
    • In the Spatializer Plugin dropdown, select the spatializer plugin you installed (e.g., "Resonance Audio").

Step 2: Configure Audio Sources

  1. Attach an Audio Source Component:

    • Select the GameObject in your scene that you want to emit sound.
    • In the Inspector window, click Add Component.
    • Search for and add an Audio Source component.
  2. Enable Spatialization on the Audio Source:

    • In the Audio Source component, locate the Spatial Blend property. Set this to a value greater than 0. A value of 1 means the sound is fully spatialized.
    • Check the Spatialize checkbox. This enables spatial audio processing for that audio source, specifically using the selected Spatializer Plugin in the Audio Settings.
  3. Adjust Spatial Settings (Important!)

    • Min Distance: The distance at which the audio starts to attenuate (get quieter) as the listener moves away.
    • Max Distance: The distance beyond which the audio won't get any quieter. This affects the loudness falloff curve.
    • Doppler Level: Simulates the change in pitch of a sound source as it moves relative to the listener (like a siren passing by).
    • Spread: Controls the apparent width of the sound source in the environment.

Step 3: Configure Audio Mixer (If Needed)

For advanced control over your spatial audio, you may want to use the Audio Mixer:

  1. Create an Audio Mixer: If you don't have one already, create a new Audio Mixer asset (Project Window -> Create -> Audio Mixer).
  2. Assign the Audio Source to a Group: In the Audio Source component, set the Output property to the desired group in your Audio Mixer. You may want separate groups for spatialized and non-spatialized sounds.
  3. Apply Effects: In the Audio Mixer, you can add effects to your groups, such as reverb, to further enhance the spatial audio experience. Resonance Audio and other plugins may offer custom effects designed for spatialization.

Example: Using Resonance Audio

Let's say you're using Resonance Audio. After importing the asset package and setting it as the Spatializer Plugin:

  1. Add an Audio Source to a GameObject (e.g., a flying drone).
  2. Set Spatial Blend to 1.
  3. Check the Spatialize box.
  4. Adjust Min Distance and Max Distance to control how the drone's sound fades as the player moves away.
  5. Add a Resonance Audio Source component for advanced settings. This component lets you control directivity (sound focuses in one direction) and occlusion (sound is blocked by objects).

By following these steps, you can add convincing spatial audio to your Unity projects, creating a more immersive and realistic soundscape for your users.

Related Articles