master volume?

Hi folks,

I’m new here, trying to get started with fmod in Unity.

I’m looking for the best way to implement a master volume setting in my game, and I see in the C++ documentation that there is a function System::getMasterChannelGroup that looks useful. I don’t see it available in the C# Unity integration though.

What would be the best way to control the master volume in Unity?

Cheers,
/Mikael

Seems the ERRCHECK method is private now?

This code works for me, but doesn’t do error checking.

	public float volume = 1.0f;
	FMOD.Studio.MixerStrip masterBus;

	void Start()
	{
		FMOD.GUID guid;
		FMOD.Studio.System system = FMOD_StudioSystem.instance.System;
		system.lookupID("bus:/", out guid);
		system.getMixerStrip(guid, FMOD.Studio.LOADING_MODE.BEGIN_NOW, out masterBus);
	}

	void Update()
	{
		masterBus.setFaderLevel(volume);
	}

Hi peter,

That solution looks good but is it still current?
I trying to use it with some minor modifications for the newer version and keep getting null pointers regarding the masterbus.

In Start

FMOD.GUID guid;
        FMOD.Studio.System system = FMOD_StudioSystem.instance.System;
        FMOD_StudioSystem.ERRCHECK(system.lookupID("/", out guid));
        FMOD_StudioSystem.ERRCHECK(system.getMixerStrip(guid, FMOD.Studio.LOADING_MODE.BEGIN_NOW, out masterBus));

On Update:

FMOD_StudioSystem.ERRCHECK(masterBus.setFaderLevel(volume));

I’m also fairly new to FMOD, and after a quick search I have been unable to find the API referenced in your comment.
Is volume a limited between 0 and 1?

I was struggling with this for a while as well. I figured it had to be something to do with the path because when I debug logged the returned GUID it was all zeroes. Turns out, when you export GUIDs from FMOD Studio the text file output contains all the paths that you need. From this, all bus paths must begin “bus:/”. Similar to the event instance paths beginning with “event:/”.

If you do:

FMOD_StudioSystem.ERRCHECK(system.lookupID("bus:/", out guid));

That should work =)

Hi Mikael,

You can retrieve the master bus using the API and control it’s volume directly. The path of the master bus is “/” so the code would look something like this:

using UnityEngine;
using System.Collections;

public class MasterVolume : MonoBehaviour 
{
	public float volume = 1.0f;
	
	FMOD.Studio.MixerStrip masterBus;
	
	void Start() 
	{
		FMOD.GUID guid;
		FMOD.Studio.System system = FMOD_StudioSystem.instance.System;
		ERRCHECK( system.lookupBusID("/", out guid) );
		ERRCHECK( system.getMixerStrip(guid, FMOD.Studio.LOADING_MODE.BEGIN_NOW, out masterBus) );
	}
	
	void Update()
	{
		ERRCHECK( masterBus.setFaderLevel(volume) );
	}
	
	void ERRCHECK(FMOD.RESULT result)
	{
		FMOD_StudioSystem.ERRCHECK(result);
	}
}

Thanks a lot!