Post-Jam Update


Yonder!

Hello!

I have just released an update to the game where a large number of the improvements suggested by fellow VimJam entrants have been implemented, as well as bugs being fixed. If you are someone that suggested these thank you very much!

I wanted to share something about building the game in WebGL with FMOD in Unity that some others may find useful.

Firstly, in many browsers audio is blocked from playing automatically, and requires some form of user input to be activated. 

Add the following code to the update method of one of your scripts in the first scene of your game (scene index: 0).

//Activate fmod on web
if (Input.anyKeyDown)
{
    if (!audioResumed)
    {
        print("Resetting audio driver based on user input.");
        var result = FMODUnity.RuntimeManager.CoreSystem.mixerSuspend();
        Debug.Log(result);
        result = FMODUnity.RuntimeManager.CoreSystem.mixerResume();
        Debug.Log(result);
        audioResumed = true;
    }
}

What this does is suspends and resumes the mixer through user input , allowing audio to be heard within the browser. I found the code here: https://alessandrofama.com/tutorials/fmod-unity/fix-blocked-audio-browsers/. (Don't forget to implement "audioResumed").

So thanks to Alessandro Famà for providing that, I wrapped this in a conditional so that when any key input is received this can be activated, rather than specifically binding this to a button like suggested.

The second problem was that my audio sliders were not working in the build, this was due to my audio system initializing (in awake), before the code above is triggered. By initialize I really mean caching the audio busses like so...

sfxBus = RuntimeManager.GetBus("bus:/SFX");
musicBus = RuntimeManager.GetBus("bus:/Music");

The easy fix is to remove this from start or awake, place it in its own method and call this in the previous code block like so...

//Activate fmod on web
if (Input.anyKeyDown)
{
    if (!audioResumed)
    {
        print("Resetting audio driver based on user input.");
        var result = FMODUnity.RuntimeManager.CoreSystem.mixerSuspend();
        Debug.Log(result);
        result = FMODUnity.RuntimeManager.CoreSystem.mixerResume();
        Debug.Log(result);
        AudioSystem.Instance.Init();  <========================
        audioResumed = true;
    }
}

At this point my build was working fine locally, but when uploading to Itch.io the audio was not working. The bank was failing to load and returning an ERR_UNSUPPORTED. I came across this fix which was a life saver...

If you look at /assets/plugins/fmod/src/Runtime/RuntimeManager.cs, line 811
#elif UNITY_WEBGL && !UNITY_EDITOR
                if (bankPath.Contains("http://"))
                {
                    Instance.StartCoroutine(Instance.loadFromWeb(bankPath, bankName, loadSamples));
                }
Should be
#elif UNITY_WEBGL && !UNITY_EDITOR
                if (true)
                {
                    Instance.StartCoroutine(Instance.loadFromWeb(bankPath, bankName, loadSamples));
                }

https://qa.fmod.com/t/fmod-and-webgl-bankloadexception/16206 <==here Brett says this will be patched in the next release, so chances are if you're reading this you wont need to do this work around anymore. Thank you Brett of FMOD!

This fixed it and now my build is finally working with sound on web through itch.io, I thought I would share this here mainly as a reminder to myself but I hope this can help someone else too. Of course this can be figured out by anyone searching Google like I just did, it took me all day to troubleshoot so hopefully it saves some time for someone else!

Files

YonderDesktopBuildV2.0.zip 28 MB
Oct 04, 2020
WebBuildV2.zip 14 MB
Oct 04, 2020

Get Yonder

Leave a comment

Log in with itch.io to leave a comment.