Platform Specifics

10. Platform Specifics

10.1 FMOD Libs on Static Platforms

Platforms such as iOS, tvOS and Switch make use of statically linked FMOD libraries. This means that the Integration cannot pick which libraries to load at runtime, this is an issue when it comes to choosing to load either the logging or release version. This also applies to choosing between running on iOS/tvOS device or their simulators.

By default the release library is linked and not the logging, meaning that if you want to use Debug_Initialize (which the Integration will use in Development builds) it will need to be changed manually.

Use these steps to change the linked library:

  • Select the release library.
  • Deselect the required platform and apply.
  • Select the logging library.
  • Select the require platform and apply.

Swapping static libs

10.1.1 Third Party Plugins

The list of plugins in the FMOD Settings only applies to platforms that support dynamic loading.

To use plugins on other platforms, they must be statically linked into the executable. Compile them into .a library files and place them under the Assets/Plugins/{Platform} folder.

Then edit the file fmodplugin.cpp to manually register the plugins. See the comments in the file for more details.

10.2 HTML5/WebGL

10.2.1 Minimum Version Requirement

The WebGL platform is only supported by the FMOD for Unity plugin in Unity 2019.1 and newer.

10.2.2 Installation

The first thing to check, is that in your project, the libfmodstudiounityplugin.bc file is located in the "\Assets\Plugins\FMOD\lib\html5" Folder of your project. For the version of FMOD that logs more information to the console, use libfmodstudiounitypluginL.bc. This can be useful when debugging and will give more verbose warnings/errors.

10.2.3 Loading banks

Banks load from the "\Assets\StreamingAssets" folder, just as they do on other platforms. FMOD Banks are not packed into the unity package, this gives more flexibility.

10.2.4 Checking that bank has loaded before playing

Loading banks from the StreamingAssets folder is an asynchronous operation.

When a bank is loaded, if Studio::System::getEvent is called too soon, the result may be FMOD_ERR_EVENT_NOTFOUND.

Make sure you use the function provided in the FMOD Studio Unity Integration FMODUnity.RuntimeManager.HasBankLoaded. This function takes the name of a bank (minus the .bank extension) For example

if (FMODUnity.RuntimeManager.HasBankLoaded("Master Bank"))
{
    Debug.Log("Master Bank Loaded");
    SceneManager.LoadScene(sceneName, LoadSceneMode.Single);
}

This is from the FMOD Unity bouncing ball example. It uses a loading screen that checks that the bank has loaded, before moving onto the next scene. Note for some browsers, you need to touch / click the screen while content is loading, for the demo to be audible, because of browser audio policies.

All banks can be checked if they have loaded, but only the last bank loaded needs to be checked, as they are loaded in order and checking the last bank will confirm that all banks have loaded.

10.2.5 FMOD for HTML5 / WebGL is single threaded!

Remember that HTML5 does not support threads. If there is stuttering audio it is a good idea to check the game's update rate, to make sure that the sound is mixed in time before the next frame operates. If the game framerate is too slow, or has large pauses, there may be stuttering audio.

The buffer size for FMOD can be increased, which will incur larger audio latency, but handle larger delays between audio mixing. To adjust buffer size use the WebGL specific setting in the Unity plugin FMOD menu under Edit Settings.

What about the asynchronous bank loading? This is a unity wrapper feature. It uses a Coroutine to load over the web, using the built in UnityEngine.Networking.UnityWebRequest feature.

10.2.6 Demo

Go to FMOD Unity bouncing ball example for a runtime example of FMOD for WebGL in Unity. Note for some browsers, you need to touch / click the screen while content is loading, for the demo to be audible, because of browser audio policies.

To download the unity package with the project and source data, go to the FMOD HTML5 Demo page on the FMOD Github page.

10.3 Callbacks on Ahead-of-time compile platforms

Managed methods that need to be marshaled to a C function pointer so that they can be called from native code have a few restrictions on AOT platforms:

  • The managed method must be a static method.
  • The managed method must have the [MonoPInvokeCallback] attribute.

For example:

    [AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))]
    static FMOD.RESULT DialogueEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, FMOD.Studio.EventInstance instance, IntPtr parameterPtr)
    {
        ...
    }

See the Unity Scripting Restrictions for more information.