FMOD Unity Integration

tutorialgame-audio-fmodgame-audio-unity

FMOD: Unity Integration

Created by Daniel Dehaan, 2021-09-26

⚠️ Warning

This document was written using FMOD Studio version 2.02.03 and Unity Editor version 2020.3.18f1 (Mac, Windows)

Unity Project Setup


  1. Create a new 3D Unity (URL) project and name it “FMOD Playground” (e.g. FA21_MUSC-601_Week-04_DDehaan).

    screen shot 2021 09 26 at 7.44.58 pm

  2. Import the Starter Assets - Third Person Character Controller.

    1. After clicking the link above, click “Add to My Assets”.

      screen shot 2021 09 19 at 5.39.31 pm

    2. Click “Open in Unity”.

      screen shot 2021 09 19 at 5.40.31 pm

    3. Make sure the Starter Assets - Third Person Character Controller package is selected and click import.

      screen shot 2021 09 19 at 5.45.13 pm

    4. If a second import window appears make sure all the assets are selected and click “Import”.

      screen shot 2021 09 19 at 6.08.13 pm

  3. If you get a pop-up warning about this project using a new input system, click “Yes”.

    screen shot 2021 09 19 at 6.11.31 pm

  4. Once the import completes, and the Unity Editor has restarted, open the demo scene found in the Project window **by navigating to Assets > StarterAssets > ThirdPersonController > Scenes and double-click “Playground”.

    screen shot 2021 09 19 at 5.48.36 pm

  5. Save the current scene as “FMOD-Playground” in the Assets > Scenes folder by right-clicking on the top-level Playground Scene within the Project Hierarchy window and choosing Save Scene As…

    screen shot 2021 09 26 at 7.46.15 pm

  6. Test the scene by clicking the play button near the top of the Unity Editor window.

    screen shot 2021 09 19 at 6.48.55 pm

Integrating Unity with an FMOD Project

  1. Go to FMOD.com/download and download both “FMOD Studio” and “FMOD for Unity” version 2.02.03

  2. Install FMOD Studio and start a new project named “FA21_MUSC-601_Week-04_First Initial Last Name_FMOD-Project” (e.g. “FA21_MUSC-601_Week-04_DDehaan_FMOD-Project”).

    screen shot 2021 09 26 at 7.52.46 pm

  3. Back in the Unity Editor, from the Menu Bar select Assets > Import > Custom Packages… and then select the FMOD for Unity file you just downloaded.

    screen shot 2021 09 26 at 7.59.24 pm

  4. Then click “Import”.

    screen shot 2021 09 26 at 8.01.53 pm

  5. After the package has been successfully imported, a setup wizard will appear, click “Start.”

    screen shot 2021 09 26 at 8.10.09 pm

  6. On the next screen confirm that “Reorganize Plugin Files” has a green checkmark next to it, then click to “Update Event References”.

    screen shot 2021 09 26 at 8.28.41 pm

  7. On the screen that appear, click “Scan”.

    screen shot 2021 09 26 at 8.30.12 pm

  8. Once the scan completes, you may close the “FMOD Event Reference Updater” window and click the “Next” button in the “FMOD Setup Wizard” window.

    screen shot 2021 09 26 at 8.31.40 pm

  9. On the next screen, click “FMOD Studio Project” then navigate to the FMOD Project you just created and click “Open”.

    screen shot 2021 09 26 at 8.11.56 pm

    screen shot 2021 09 26 at 8.12.27 pm

  10. Then click “Next”.

    screen shot 2021 09 26 at 8.17.20 pm

  11. The next screen will prompt you to replace any native “Audio Listener” components with FMOD’s Audio Listener components. For now, just click “Next’. We will do this manually in just a moment.

    screen shot 2021 09 26 at 8.19.23 pm

  12. On the next screen, click the button to “Disable built in audio”. Then click “Next”.

    screen shot 2021 09 26 at 8.21.46 pm

  13. On the next screen, confirm that no audio sources should have been found and click “Next”.

    screen shot 2021 09 26 at 8.23.10 pm

  14. The final screen provides information about what you should do if you are working on a collaborative team that uses a system for managing changes to their shared files. We are not, so we can just click “Next”.

    screen shot 2021 09 26 at 8.25.43 pm

  15. With everything but the Listener step completed, you may now close the FMOD Setup Wizard window.

    screen shot 2021 09 26 at 8.34.04 pm

  16. Lastly, we need to replace the native Audio Listener with the FMOD Studio Listener component. To do this, select the MainCamera game object in the Hierarchy window for the FMOD-Playground scene.

    screen shot 2021 09 26 at 8.39.18 pm

  17. Then, over in the inspector window, find and remove the “Audio Listener” component.

    screen shot 2021 09 26 at 8.40.20 pm

  18. Finally, add a new “FMOD Studio Listener” component to the MainCamera game object.

    screen shot 2021 09 26 at 8.41.28 pm

  19. That’s it! You have now successfully integrated Unity and FMOD.

Adding Background Music

  1. In your FMOD Project, create a new 2D Timeline Event and call it “Music_Background”.

    screen shot 2021 09 26 at 8.46.45 pm

  2. Switch to the Assets tab and drag-and-drop your background music file into a new folder called “Music”.

    Music Elevator by Jay_You Id-460432.wav.zip

    screen shot 2021 09 26 at 8.48.39 pm

  3. Then drag-and-drop that asset onto the Background_Music even you just created.

    screen shot 2021 09 26 at 8.50.47 pm

  4. Loop the full duration of the audio asset by right-clicking on the waveform and selecting “New Loop Region”.

    screen shot 2021 09 26 at 8.51.48 pm

  5. Before this event and its associated assets become available to our Unity project, we have to first assign the event to a Bank, and build the FMOD resource that will be include in the Unity project. To do this, right-click on the “Background_Music” event and assign it to the “Master” bank.

    screen shot 2021 09 26 at 8.54.36 pm

  6. Then, from the Menu Bar, select File > Build All Platforms

    screen shot 2021 09 26 at 8.55.23 pm

  7. Then save the FMOD project.

  8. Back in Unity, select FMOD in the Menu Bar and choose “Refresh Banks”.

    screen shot 2021 09 26 at 9.01.42 pm

  9. Next, add an empty game object to the FMOD-Playground scene and call it “Background_Music”.

  10. Select the new “Background_Music” game object and add an “FMOD Studio Event Emitter” component.

    screen shot 2021 09 26 at 8.59.11 pm

  11. In the new “FMOD Studio Event Emitter” comment set the

    • Play Event = “Object Start”
    • Stop Event = “Object Destroy”
    • Event = “event:Background_Music”

    screen shot 2021 09 26 at 9.02.44 pm

  12. Finally, click the “Play” button to test for your background music.

Adding Footsteps


  1. Navigate to Assets > Standard Assets > ThirdPersonController > Character > Animations > Locamotion—Walk_N.anim

    adding footstesp   step 1

  2. Expand the Events section.

    footsteps   step 2

  3. Move the model into a good position to see the feet.

    • Option/Alt + click + drag = turn camera
    • Click+Drag = slide camera
    • Option/Alt + mouse wheel up/down to zoom in/out
  4. Drag on Play Ruler (above model view) to find the first footfall and add a “Step” event by clicking the Add Event button.

  5. Repeat the previous step for all footsteps.

  6. When a “Step” event has been added to all animated footsteps, click “Apply”.

    click apply

  7. Select the PlayerArmature game object in the Hierarchy window, and, if one does not already exist, add an Audio Source component.

  8. Add a new Script Component named “Audio_Trigger_Animation_Event_Step” to the PlayerArmature game object.

  9. In the Project window, create a new Scripts folder inside the main Assets folder and move your new Animation_FMOD_Event_Trigger **inside of the new folder.

  10. Open new Script in Visual Studio.

  11. In Visual Studio edit the script so it matches the one shown below:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Animation_FMOD_Event_Trigger : MonoBehaviour
    {
        public FMODUnity.EventReference fmodEventStep;
    
        private void Step()
        {
            FMODUnity.RuntimeManager.PlayOneShot(fmodEventStep);
        }
    }
  12. Save and close the script.

  13. Back in FMOD Studio, create a new 2D Action called “Player_Step” and assign it to the Master bank.

    screen shot 2021 09 26 at 10.14.16 pm

  14. In the Assets tab, drag-and-drop the footstep audio files into a new folder called “Footsteps” inside of another new folder called “Player”.

    Footstep Audio Files.zip

    screen shot 2021 09 26 at 10.13.39 pm

  15. Then, back inside the new Player_Step event, right-click and add a new Multi Instrument.

    screen shot 2021 09 26 at 10.15.30 pm

  16. Next, drag-and-drop all the footstep assets inside the new Multi Instrument.

    screen shot 2021 09 26 at 10.16.50 pm

  17. Test the event in FMOD by clicking the play button a few times. You should hear a different footstep on each click of the play button.

  18. Before testing everything back in Unity, be sure to Build For All Platforms and save the FMOD project.

    screen shot 2021 09 26 at 8.55.23 pm 1

  19. Back in Unity, refresh the FMOD Banks.

    screen shot 2021 09 26 at 9.01.42 pm 1

  20. Return to the Animation_FMOD_Event script component in the inspector window and select the new Player_Step event for the FMOD Event Step parameter.

    screen shot 2021 09 26 at 10.25.59 pm

  21. Finally, play the game in Unity and see if you can hear the footsteps. screen shot 2021 09 26 at 10.30.03 pm screen shot 2021 09 26 at 10.31.26 pm

Controlling FMOD Parameters


FMOD Parameters could be controlled by almost anything in Unity, but to keep things simple we’ll setup some Box Triggers to trigger specific FMOD parameter values.

Box Triggers are invisible game objects within the scene that are used to trigger events whenever a player moves through them.

Let’s create a box trigger so that whenever our player walks through the short tunnel the background music fades out, and an owl “hoots” randomly for as long as the player remains inside the tunnel.

  1. Begin by bringing the short Tunnel_Prefab game object into focus by

    1. Selecting it in the Hierarchy window under Environment > Greybox > Tunnel_Prefab
    2. Then hover the cursor over the Scene window and pressing the ‘f’ key

  2. Right click on the Tunnel_Prefab object in the Hierarchy window and create a new 3D Object > Cube game object named “Box_Trigger”.

    add cube to tunnel

  3. With the new Box_Trigger object selected in the Hierarchy window, navigate to the Inspector widow and adjust all of the following parameters to…

    • Transform > Position x = 0, y = 0, z = 1.25

    • Transform > Scale x = 2.5, y = 6, z = 2.5

      screen shot 2021 09 19 at 10.41.27 pm

    • Disable its Mesh Renderer

      screen shot 2021 09 19 at 10.41.43 pm

    • And enable the *Box Collider’s ‘*Is Trigger’ option.

      screen shot 2021 09 19 at 10.42.53 pm

  4. With the Box_Trigger game object still selected in the Hierarchy window, add a two “FMOD Studio Global Parameter Trigger” components. The first will set the Location parameter’s value to 1 when the player enters the box trigger. And the second will set the Location parameter’s value back to 0 when the player exits the box trigger.

    screen shot 2021 09 26 at 11.36.11 pm

  5. Now test to see the parameter’s value changes when the player moves in and out of the box trigger.