How do I know that Bank has finished loading?

I’m trying to make on-demand Bank loading for a Unity project for WebGL.

I have read the following article:


These articles use a while loop to wait for the Bank to finish loading, but apparently this is not flexible enough.
For example, I have two Events that need to be played and they belong to different Banks. I want the Event to start playing as soon as the Bank it needs is loaded, whereas using the HaveAllBanksLoaded() method means that I have to wait for all the Banks to finish loading before I can play the Event.

It seems like adding a callback function to the LoadBank method would be a good way to do this, but it would require me to make some changes to the RuntimeManager code, and handling this part of the functionality could become cumbersome if and when we subsequently update the version of the FMOD Unity integration.
Other than that, is there a better way for me to accomplish this?

Also, I found a line of code in the RegisterLoadedBank method in the RuntimeManager that looks like this:
Instance.loadedBanks.Add(bankName, loadedBank);
According to the C# documentation, the Add method of a Dictionary throws an exception if the same value is passed in.

And before that, only the Instance.loadedBanks.ContainsKey(bankId) check was passed at the beginning of the LoadBank() method. And the execution of RegisterLoadedBank() method in loadFromWeb() method is after yield return www.SendWebRequest();. Is this likely to trigger an exception due to asynchronous loading?

As a side note, there is also a HasBankLoaded() method in the RuntimeManager that checks to see if a particular Bank has finished loading.
But this also requires the use of a while loop to check when the loading has finished.
In my opinion, I would try to avoid using high frequency while loops to check in my code. Especially since I might need to call this method in another language (e.g. in TypeScript) than in the C# code of the Unity project.

This is actually already the default behavior of FMOD. When you load a bank, only the bank metadata is loaded. The event’s sample data is then loaded when a call to Studio::EventDescription::createInstance is made, and a that point, the event will be ready to start playing. So, from your description, I don’t think there is no need for you to create a system that dynamically plays events once a bank is loaded.

When registering the newly loaded bank, we check the load result. If that bank has already been loaded, we don’t add it to the dictionary, so I don’t see anything that would cause a bank to be double-added to that Dictionary.

Perhaps you could move the while loop into a coroutine, as we do in our Asynchronous Loading example. The while loops in there aren’t high frequency- they only run once per frame and then yield if the bank hasn’t finished loading. Alternatively, you can call Studio::System::flushSampleLoading, which will block until all sample loading has completed.