Get a bus list from a bank

Hello, I am trying a create a mixer in unity allowing to set he volume of the buses of the project.
To make it, I’m trying to get the list of buses in the fmod bank.

The problem is that I get an ERR_INVALID_HANDLE error. This probably seem that he way I’m referring to the current fmod system isn’t OK.

Here is the code

Blockquote
[FMODUnity.BankRef]
public List Banks;

private FMOD.Studio.Bus[] myBuses = new FMOD.Studio.Bus[12];
private string busesList;
private string buf;
private FMOD.Studio.Bank myBank;

private string BusPath;
public FMOD.RESULT busListOk;
public FMOD.RESULT sysemIsOk;

void Start()
{
    foreach (var bank in Banks)
    {
        FMODUnity.RuntimeManager.StudioSystem.getBank(bank, out myBank);
        busListOk = myBank.getBusList(out myBuses);
        if (myBuses.Length > 0 )
        {
            foreach (var bus in myBuses)
            {
                bus.getPath(out buf);
            }
        } 
    }
}

Blockquote

If not OK does somebody can explain me how to declare properly the system?

Thanks

Hi,

You are using the right FMOD System to get the buses.

I would recommend getting an array of all the banks, to get the array use:

FMODUnity.RuntimeManager.StudioSystem.getBankList(out bankList);

bankList being an array of FMOD.Studio.Bank[]. Then looping through this array checking the bankList[i].getBusCount() to make sure it has any buses. This way you are sure that you are checking all the banks and getting all their buses.

I will link the Bank API and the Bus API for explanations of the functions I am using.

Getting the FMOD.RESULT from each FMOD function might give more insight to which function is failing rather than having a public variable.

If you are still having issues I can share more code.

Hope this helps!

Hi,

Thanks for the answers,

OK and this also avoid to try to load bank that are already loaded.

For those interested, here is the fixed code:

void Start()
{
        FMODUnity.RuntimeManager.StudioSystem.getBankList(out FMOD.Studio.Bank[] loadedBanks);
        foreach (FMOD.Studio.Bank bank in loadedBanks)
        {
            bank.getPath(out string path);
            busListOk = bank.getBusList(out myBuses);
            bank.getBusCount(out busCount);
            if (busCount > 0)
            {
                foreach (var bus in myBuses)
                {
                    bus.getPath(out busPath);
                }
            }
        }
    }
1 Like