Getting Started With FMOD Banks | Part 4

It's Time To Finish This Once & For All!

Last time, we created banks for multiple music events and then loaded the Master Bank into our game during ‘Initialization’. Our banks looked like this:

Our goal is to load each bank as each level begins, and then unload them as the levels finish. This ensures that the player will hear a different piece of music per level they play through, whilst also housing each bank (and music it contains) in our systems RAM individually as they’re needed, freeing up space for other assets.

The easiest way to do this is with a Studio Bank Loader component.

A Studio Bank Loader is a Unity component that FMOD provides for us.

We can attach it to a gameobject and then tell it to load and unload specific banks into our game by triggering particular functions.

To use it, we first need to choose which function we’d like to use to load our banks with.

Load

Now let’s pretend that I’ve attached this Studio Bank Loader component to an object in the first scene of our game, which happens to be the main menu.

Remember we want our bank containing our main menu music to load at the start, so let’s look at the functions we can choose from to achieve this.

If we use the Object Start function, our bank will load on the first frame that is run for this scene.

We can then tell the music within it to begin to play straight after using code, so we’ll use this function.

Unload

Next we need to choose a function which will unload our bank once the scene has ended.

Now whilst we don’t have a function to choose from that can detect when the scene ends, we do have one that can detect when the object we’ve attach this component to will be destroyed – Object Destroy.

Why would we want to check for the objects destruction?

Well because unless we tell it otherwise, our GameObject will be destroyed by Unity automatically when the scene that we’re currently editing ends, and Unity loads a new one.

So long as we don’t tell our GameObject to destroy itself before this happens, we can be sure that the Object Destroy function will trigger our bank to unload once our scene ends.

Preload Sample Data

Next we need to decide whether or not we want to pre-load the sample data that the bank contains.

We learnt in the last email that this would mean that the sample data being used for our music event would be loaded into RAM at the same time as the rest of the Banks data, which in this case would be when the first frame of this scene is run.

Alternatively, we can leave this section blank, meaning the sample data used for the events within the bank would be loaded once each event is told to play by our game. This frees up RAM space until that happens, but also causes a time delay between when we play each event and when our player hears them.

This will always be a decision to be made based on the circumstances of your game and the events that the bank will be playing.

When working on your own projects, it will be up to you to make that judgement call.

Just remember the ultimate goal of bank loading… 

The Goal Is To Limit The Amount Of Audio Loaded Into Our Systems RAM At Any Given Moment During Runtime.

 

Choose which ever options insures the best efficiency for your system and performance of your game based on..

  • WHEN you plan on loading the bank.
  • HOW LONG before you trigger the events contained within that bank 
  • HOW IMPORTANT is it for the player to hear the audio in those events play as soon as you tell them to.
  • HOW MUCH space in your systems RAM you and the other developers of the game have to work with.

In the context of our example, because our bank only contains one event, it makes things a little easier.

We’re going to tell this music to play straight away, therefore it needs to be loaded in as soon as the bank has finished loading.

So even if we choose not to pre-load the sample data for our music, it will still be loaded in at the same time as the rest of the banks data, as it will be told to play instantly after.

But even though it doesn’t really matter for us, I’m going to play it safe and pre-load the data.

Choosing Which Banks To Load

Finally we move onto the easy bit. Selecting the banks that we want to load using our Studio Bank Loader.

For each bank you wish to load, click ‘Add Bank‘ and then choose a bank.

Remember that we’re loading banks for our Main Menu scene, so we’ll select the Main Menu bank.

So To Recap

Thanks to our Studio Bank Loader component, our Main Menu bank will be loaded into RAM once the first frame of our scene is ran using the ‘Object Start’ function.

Our bank contains a music event, which we can also tell to play, using the Start function, on the first frame once the bank has loaded in another script.

The sample data (our music wav file) will be pre-loaded alongside the rest of the data inside our bank, so that it’s ready to be played straight away.

Once the scene ends, the object our Studio Bank Loader is attached to will be destroyed, triggering the ‘Object Destroy’ function to unload our bank, and the music event with it, from Ram which will free up space for other music events and banks to be used in the next scene. 

Congratulations! You Can Now Optimize Your Unity Game By Loading FMOD Banks Containing Audio Events For Specific Scenes Into RAM As They’re Needed.