Plugins

9. Plugins

If your FMOD Studio project uses any plugins, you must add them to your Unity project before you can load any of your content at runtime. Depending on the target platform, FMOD for Unity supports both dynamic and static plugins.

The ResonanceAudio plugins come bundled with FMOD for Unity, and can be used as a guide for adding other plugins.

9.1 Dynamic Plugins

Dynamic plugins are defined in native dynamic libraries, each of which can contain one or more plugins (for example, "resonanceaudio.dll" contains the Windows versions of the ResonanceAudio plugins). Each platform requires its own version of the dynamic library; put this in the corresponding platform folder under Assets/Plugins/FMOD/platforms/{Platform}/lib, next to the FMOD libraries.

"Dynamic Plugin Library"

You need to change the plugin's import settings to match the platform and CPU architecture that the plugin is compiled for. To do this, select the plugin in the Unity Editor to display its import settings in the inspector window. Then tick the plugin's target platform in the "Include Platforms" list and untick all the other platforms. Finally, set the target architecture in the "CPU" dropdown to match your plugin's target architecture, and click on the "Apply" button to save the changes to the plugin's import settings. Here is an example of the import settings for a plugin compiled for the Android platform with an ARM64 CPU architecture:

"Dynamic Plugin import settings"

The Dynamic Plugins list in the FMOD for Unity settings specifies which dynamic plugins to load at initialization time. Add the name of the plugin's dynamic library without the extension (for example, "resonanceaudio" instead of "resonanceaudio.dll"), and FMOD will determine which file to use based on the current platform.

"Dynamic Plugin List"

9.2 Static Plugins

FMOD for Unity supports loading static plugins when running on the IL2CPP scripting backend. This is the only way to load plugins on platforms that don't support dynamic libraries (such as iOS, tvOS, and Nintendo Switch).

The Static Plugins list in the FMOD for Unity settings specifies which static plugins to load at initialization time. Add the name of the plugin's _GetDSPDescription function or functions (for example, FMOD_ResonanceAudioSource_GetDSPDescription, FMOD_ResonanceAudioSoundfield_GetDSPDescription, and FMOD_ResonanceAudioListener_GetDSPDescription), and FMOD will generate C# code to load the plugin.

"Static Plugin List"

Static plugins must be statically linked into the executable. You can implement this by including source code or static libraries in your Unity project.

9.2.1 Source Code

To include a plugin in your Unity project as source code, the plugin must be written in C++. Place the C++ source files, including any of the necessary includes, in a location of your choice within the Assets folder, and Unity will automatically build these files and link them into the executable. Unlike Dynamic Plugins, statically loaded source code plugins can be left with the default platform settings of "Any Platform".

"Static Plugin Source Code"

9.2.2 Static Libraries

To include a plugin in your Unity project as static libraries, you will need a static library for each platform. Put these static libraries in the corresponding platform folders under Assets/Plugins/FMOD/platforms/{Platform}/lib, next to the FMOD libraries.

"Static Plugin Library"

As with Dynamic Plugins, you also need to change the plugin's import settings to match the platform and CPU architecture that the plugin is compiled for.

9.3 FMOD Haptics Setup

The FMOD Haptics plugin can be used to generate haptic vibrations authored in Meta Haptics Studio. In order for the FMOD integration to load the plugin it must be added to the Dynamic Plugins list as stated in Dynamic Plugins

Loading the fmod_haptics dynamic library in the FMOD integration settings

9.3.1 Auditioning In-Editor

Auditioning in-editor is supported with the same platform and device combinations specified in the Auditioning Support section of the FMOD Studio Instrument Reference. Meta Quest controllers cannot be auditioned in-editor, and require additional configuration for use in a built application, which is covered below.

9.3.2 Packaging the FMOD Haptics plugin in your builds

The FMOD Haptics dynamic library is disabled by default, but needs to be enabled on your relevant platform for it to be packaged into the build. Here is an example of how to enable the fmod_haptics library on Windows and Quest.

Windows

  1. Navigate to Assets\Plugins\FMOD\platforms\win\lib\x86_64
  2. Select the fmod_haptics plugin
    libfmod_haptics library location
  3. Set the CPU to x64
    FMOD Haptics Enable Plugin

Quest

  1. Navigate to Assets\Plugins\FMOD\platforms\android\lib\quest
  2. Select the libfmod_haptics plugin
    libfmod_haptics library location
  3. Set the CPU to ARM64
    FMOD Haptics Enable Plugin

9.3.3 Supporting VR Platforms

Dependencies

OpenXR Plugin (Quest Only)

The OpenXR Plug-in must enable the "FMOD: Haptics" feature for haptic playback on Meta Quest. The following settings are only accessible when the Android platform is active.

  1. In the Unity menu, select "Edit > Project Settings > XR Plug-in Management"
  2. Select OpenXR as the Plug-in provider
    XR Plugin Management
  3. In the left pane, expand "XR Plug-in Management" and select "OpenXR"
  4. Check the "FMOD: Haptics" feature group
    OpenXR Feature Groups
  5. Ensure you have any relevant interaction profiles enabled for the devices you are targeting
    OpenXR Interaction Profiles

You should now be able to trigger vibrations on Meta Quest controllers by playing any event containing a haptics instrument.

Enable VR (PSVR2 only)

PSVR requires an additional configuration step for use with FMOD Haptics. Create a new callback handler, following the steps in the Callback Handler example, and make a call to FMOD_Haptics_VR_Configure.

using System;
using UnityEngine;
using System.Runtime.InteropServices;

[CreateAssetMenu(menuName = "PSVR Callback Handler")]
public class PSVRCallbackHandler : FMODUnity.PlatformCallbackHandler {
    public override void PreInitialize(FMOD.Studio.System studioSystem, Action<FMOD.RESULT, string> reportResult)
    {
#if PLATFORM_PS5 && !UNITY_EDITOR
        FMOD.RESULT result = FMOD_Haptics_VR_Configure(true);
        reportResult(result, "FMOD_Haptics_VR_Configure");
#endif
    }

    [DllImport("libfmod_haptics.prx")]
    private static extern FMOD.RESULT FMOD_Haptics_VR_Configure(bool enableVr);
}