#Hot-loading WAV files

1 messages · Page 1 of 1 (latest)

balmy vale
#

I started asking around on the BepInEx discord and they directed me here because this is a core unity concept - i'm trying to hotload wav files to replace audio assets as they play in game - it successfully swaps the soundclip with something else but no audio actually plays.

            var www = UnityWebRequestMultimedia.GetAudioClip(wav, AudioType.WAV);
            www.SendWebRequest();
            var clip = DownloadHandlerAudioClip.GetContent(www);
            
            if (www.result != UnityWebRequest.Result.Success)
            {
                Debug.Log(www.error);
                return true;
            }```
desert wave
#

The first thing that jumps out is that you're not exactly waiting for the web request to finish, you're just immediately going to grab the data from it

#

try putting it in a coroutine and doing yield return www.SendWebRequest

balmy vale
#

alright i'm giving it a test

#

the original clip is no longer playing but the new audioclip is also not playing

balmy vale
#

okay, did some digging

#
[Info   : DebugPlus] ====== NAME ======
[Info   : DebugPlus] weap_trigger_empty : weap_trigger_empty
[Info   : DebugPlus] ====== LENGTH ======
[Info   : DebugPlus] 0.1756009 : 0
[Info   : DebugPlus] ====== AMBISONIC ======
[Info   : DebugPlus] False : False
[Info   : DebugPlus] ====== CHANNELS ======
[Info   : DebugPlus] 1 : 0
[Info   : DebugPlus] ====== FREQUENCY ======
[Info   : DebugPlus] 44100 : 0
[Info   : DebugPlus] ====== LOADSTATE ======
[Info   : DebugPlus] Loaded : Loaded
[Info   : DebugPlus] ====== LOADTYPE ======
[Info   : DebugPlus] DecompressOnLoad : DecompressOnLoad
[Info   : DebugPlus] ====== LOADINBACKGROUND ======
[Info   : DebugPlus] True : False
[Info   : DebugPlus] ====== PRELOADAUDIODATA ======
[Info   : DebugPlus] True : True
[Info   : DebugPlus] ====== SAMPLES ======
[Info   : DebugPlus] 7744 : 0
[Info   : DebugPlus] ====== HIDEFLAGS ======
[Info   : DebugPlus] None : None```
#

right side is replacement file, left side is original

#

this also occurs when using the game's original audio files

woven idol
#

Did you correct the loading logic to wait for the request to complete? Async/coroutine?

vapid shore
# balmy vale yes

It is possible that you must wait for processing of the data after waiting for the request to be done. Then dispose www.

{
    var www = UnityWebRequestMultimedia.GetAudioClip(wav, AudioType.WAV);
    //wait for request
    yield return www.SendWebRequest();

    if (www.result != UnityWebRequest.Result.Success)
    {
        Debug.Log(www.error);
    }
    else
    {
        //wait for post processing content
        while (!www.downloadHandler.isDone)
            yield return null;
        //retrieve result
        var clip = DownloadHandlerAudioClip.GetContent(www);
        //...
    }
    www.Dispose();
}```
balmy vale
#

oh, disposing is handled if you use a using block

vapid shore
#

Yes, did it help?

balmy vale