# HasBankLoaded causes NullReferenceException when RuntimeManager is not initialized

**URL:** <https://qa.fmod.com/t/hasbankloaded-causes-nullreferenceexception-when-runtimemanager-is-not-initialized/15974>\
**Category:** Unity\
**Created:** [July 15, 2020, 5:51am UTC](https://qa.fmod.com/t/hasbankloaded-causes-nullreferenceexception-when-runtimemanager-is-not-initialized/15974 "2020-07-15T05:51:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhys\_vdw](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/rhys_vdw/32/2454_2.png) [@rhys\_vdw](https://qa.fmod.com/u/rhys_vdw)\
**Post date:** [July 15, 2020, 5:51am UTC](https://qa.fmod.com/t/hasbankloaded-causes-nullreferenceexception-when-runtimemanager-is-not-initialized/15974/1 "2020-07-15T05:51:18Z")

</div>

**FMOD Unity integration version:** 2.01.01

```
public static bool HasBanksLoaded
{
    get
    {
        return Instance.loadedBanks.Count > 1; 
    }
}

public static bool HasBankLoaded(string loadedBank)
{
    return (instance.loadedBanks.ContainsKey(loadedBank));
}

```

Note that `HasBankLoaded` refers to `instance`, rather than `Instance`, the former of which does not lazy-init the `RuntimeManager`.

To work around this mistake I used the following hack:

```
IEnumerator Start() {
  // Wait for all master banks to load. Ths is requred for web where banks
  // are loaded in asynchronously.
  //
  // https://www.fmod.com/resources/documentation-api?version=1.10&page=content/generated/engine_new_unity/html5_webgl.html
  var banks = FMODUnity.Settings.Instance.MasterBanks;

  // NOTE: Forcing initialization of FMOD which otherwise does not start due
  // to internally referencing `instance` instead of `Instance`.
  var _ = FMODUnity.RuntimeManager.HasBanksLoaded;

  while (!_isFmodSoundBankLoaded) {
    _isFmodSoundBankLoaded = banks.All(FMODUnity.RuntimeManager.HasBankLoaded);
    yield return null;
  }

```

This definitely seems like an error, and only showed up (in an otherwise working project) when I removed the FMOD listener component from the scene. Previously it called `AddListener` which internally called `StudioSystem.setNumListeners` which _happened_ to cause the system to initialize before my first call to `HasBankLoaded`.

---

<div class="post-metadata">

**Author:** ![mathew](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mathew/32/431_2.png) [@mathew](https://qa.fmod.com/u/mathew)\
**Post date:** [July 16, 2020, 1:44am UTC](https://qa.fmod.com/t/hasbankloaded-causes-nullreferenceexception-when-runtimemanager-is-not-initialized/15974/2 "2020-07-16T01:44:22Z")

</div>

Thanks for the bug report, we’ll get that fixed up.

---

<div class="post-metadata">

**Author:** ![rhys\_vdw](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/rhys_vdw/32/2454_2.png) [@rhys\_vdw](https://qa.fmod.com/u/rhys_vdw)\
**Post date:** [July 16, 2020, 7:41am UTC](https://qa.fmod.com/t/hasbankloaded-causes-nullreferenceexception-when-runtimemanager-is-not-initialized/15974/3 "2020-07-16T07:41:47Z")

</div>

Thanks for the quick response @mathew.

While I’m here I’d like to give some feedback on this API too…

Would you consider renaming `HasBanksLoaded` to `HasAnyBankLoaded`, and add `HaveAllBanksLoaded` which does something like I’m doing here?

```auto
bool HaveAllBanksLoaded() {
  var banks = Settings.Instance.MasterBanks;
  for (var i = 0; i < banks.Length; i++) {
    if (!HasBankLoaded(banks[i])) return false;
  }
  return true;
}

```

“HasBanksLoaded” is a confusing name, and the method behaviour is surprising (and has dubious usefulness).

---

<div class="post-metadata">

**Author:** ![mathew](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mathew/32/431_2.png) [@mathew](https://qa.fmod.com/u/mathew)\
**Post date:** [July 17, 2020, 12:31am UTC](https://qa.fmod.com/t/hasbankloaded-causes-nullreferenceexception-when-runtimemanager-is-not-initialized/15974/4 "2020-07-17T00:31:47Z")

</div>

Thanks for the feedback, we’ll look into clearing that up.  
Any API changes will need to be on a major version though.
