I’m playing back sound through FMOD which I want to switch from 2D/3D mode on the fly. To do that I’ve got some code like this:
// Nb. `_channel` is an `FMOD.Channel`
if (positional)
{
Check(_channel.setMode(MODE._3D | (MODE)RolloffMode), "Failed `setMode`", true);
Check(_channel.set3DMinMaxDistance(MinDistance, MaxDistance), "Failed `set3DMinMaxDistance`", true);
}
else
{
Check(_channel.setMode(MODE._2D), "Failed `setMode`", true); // <-- ERROR HERE!
}
However, when I run this I’m getting errors on the final line:
Failed setMode
. FMOD Result: ERR_NEEDS3D
This appears to be telling me that I simply cannot set this channel into 2D mode! What am I doing wrong here?
Edit: I’m calling this every frame. So is the problem that I’m calling _channel.setMode(MODE._2D)
on a channel which is already 2D?
You should be able to set the mode of a channel at runtime, what version of FMOD are you using?
Are you playing these channels using the Core API, via System.createSound
, or the Studio API, creating events and getting their channels using EventInstance.getChannelGroup
? If you are using the Studio API you can try toggling the byppass state of the spatializer (“FMOD Pan” dsp):
void Toggle2D3D(FMOD.Studio.EventInstance eventInstance)
{
eventInstance.getChannelGroup(out FMOD.ChannelGroup cg);
cg.getNumDSPs(out int numDSPs);
// Linear search for spatializer
for(int i = 0; i < numDSPs; ++i)
{
cg.getDSP(i, out FMOD.DSP dsp);
dsp.getInfo(out string dspName, out uint version, out int channels,
out int configwidth, out int configheight);
// "FMOD Pan" is the Spatializer DSP setup in Studio
if (dspName.Contains("FMOD Pan"))
{
dsp.getBypass(out bool bypassed);
dsp.setBypass(!bypassed);
}
}
}