I am using Wwise Unity Integration Version 19, integration bundle 2019.2.6.1867, based on WwiseSDK 2019.2.6 Build 7381.
I have an AK.Wwise.Event that is localized for multiple languages.
I can verify that if I perform these steps:
- Unload the soundbank that contains the event with: AkBankManager.UnloadBank(bankName)
- Change the Language with: AkSoundEngine.SetCurrentLanguage(newLangName)
- Wait a few frames...
- Re-load the soundbank with: AkBankManager.LoadBank(bankName)
- Finally call event.Post(...)
That the correct version plays for the language in question. So far so good
Now as an experiment I want to try and do this dynamically.
Basically if the event in question is currently playing (so I have its playingID and have previously Post-ed it) and the language is changed, I want to stop the event and re-start its new localized version at the same timestamp it just left off at, effectively allowing the user to switch between languages on the fly.
I have a proof of concept of this working mostly, but unfortunately for some reason I randomly get WWise: Media was not loaded for this source errors.
The basic approach:
- I have a simple dropdown UI for testing where I can pick from all the languages I have files for in the bank under the given name.
- Based on user input it calls AkSoundEngine.SetCurrentLanguage(...)
- Since AK::StreamMgr::AddLanguageChangeObserver does not seem to be exposed do the C# API, I am detecting when the language changes by regularly checking AkSoundEngine.GetCurrentLanguage().
- Once a change is observed, I reload the event's bank(s) using a coroutine to ensure the bank loads completely: https://gist.github.com/JohannesMP/2b6b58e5a5bce4b273c8b869aba3ead1
- I manage my AK.Wwise.Event with its own component that now receives the AkCallbackType.AK_EndOfEvent callback, as a result of the event being stopped since its bank was unloaded.
- I waits a few frames to make sure the bank is definitely done loading, and then post the event again.
- And finally we use AkSoundEngine.SeekOnEvent to set the time to where it was before the language change.
As mentioned, seemingly at random I will get a WWise: Media was not loaded for this source error when the event is re-posted after the soundbank finished reloading, which I cannot explain. This even happens if I extend the delays between unloading the bank, loading the bank, and re-Post-ing the event to many seconds. More curious is that once a given AK.Wwise.Event has entered this 'error' state, I can try calling Post as many times as I want, it will continue to insist that the media is not loaded. Only by switching to a different language (which reloads the bank) and back again does it seem to recover.
So my question here is, what is causing this error, and how can I avoid it?
I'm positive it's not a matter of not waiting long enough for the bank to finish loading, and it seems to be fairly random when it happens, but seems to be more common if I switch back and forth between languages a few times.