Bug Report: In Unity, the distance adjustment set for event audio in FMOD Studio does not work as expected

When I retrieve the distance using getMinMaxDistance and set it using set3DMinMaxDistance, only the functionality of muting sound beyond the distance works. In FMOD Studio, adjusting the distance applies volume attenuation accordingly, but when modifying this value in Unity, only the muting effect works, and no changes in attenuation are observed.

I tried obtaining the channelGroup and using setMode(FMOD.MODE._3D | FMOD.MODE._3D_LINEARROLLOFF);, but this only works for non-event cases, so it was not meaningful.
Even modifying the properties using:
setProperty(FMOD.Studio.EVENT_PROPERTY.MINIMUM_DISTANCE)
setProperty(FMOD.Studio.EVENT_PROPERTY.MAXIMUM_DISTANCE)
did not affect the attenuation.

Summary:

Case 1:

When the distance is set to 1–20 in FMOD and the bank file is built:

  1. At a distance of 1, the sound is loud as expected.
  2. At a distance of 20, the sound is properly attenuated and quieter.
  3. After setting the distance to 1–100 using setProperty or set3DMinMaxDistance, the sound still disappears at a distance of 30 (attenuation is not applied correctly).
  4. When the distance is set to 1–10 using setProperty or set3DMinMaxDistance, the sound is still loud at 9, but it suddenly mutes when moving to 11 (attenuation is not applied correctly).

Case 2:

When the distance is set to 1–100 in FMOD and the bank file is built:

  1. At a distance of 1, the sound is loud as expected.
  2. At a distance of 100, the sound is properly attenuated and quieter.
  3. After setting the distance to 1–20 using setProperty or set3DMinMaxDistance, the sound is still loud at 19, but it suddenly mutes at 21 (attenuation is not applied correctly).
  4. When the distance is set to 1–1000 using setProperty or set3DMinMaxDistance, the sound should still be loud at 100. However, the attenuation is not applied correctly, and the sound is already inaudible.

It seems there is a bug in the functionality of setProperty and set3DMinMaxDistance. When will this issue be resolved?

I have searched through past discussions, but the only advice was to use these functions without properly addressing the problem. It appears the attenuation functionality is not correctly updated.

Please address this critical functionality omission bug and improve it.

Here is a part of the code where attenuation is not applied correctly:

        if (eventDescription.isValid())
        {
            instance = GetInstance();

            if (instance.isValid() && is3D)
            {
                FMOD.RESULT result = instance.getChannelGroup(out FMOD.ChannelGroup channelGroup);
                if (result == FMOD.RESULT.OK)
                {
                    //Debug.Log("Channel group successfully retrieved.");
                    //channelGroup.setMode(FMOD.MODE._3D | FMOD.MODE._3D_LINEARROLLOFF);
                    channelGroup.set3DMinMaxDistance(MinMaxDistance.x, MinMaxDistance.y);
                }

                {
                    RuntimeManager.AttachInstanceToGameObject(instance, target);
                    instance.set3DAttributes(RuntimeUtils.To3DAttributes(target));
                }

                instance.setProperty(FMOD.Studio.EVENT_PROPERTY.MINIMUM_DISTANCE, MinMaxDistance.x);
                instance.setProperty(FMOD.Studio.EVENT_PROPERTY.MAXIMUM_DISTANCE, MinMaxDistance.y);

            }
        }

Currently, due to this bug, I have to manually adjust the distance settings for all audio events in FMOD, rebuild them, and then check them in Unity, which is very inconvenient.
If the attenuation functionality works correctly, I would be able to test it in Unity at runtime.
Please assist with this issue.

Hi,

Thank you for the detailed information.

Could I please grab the Unity and integration version you are using to test on my side?


Could I also get a screen shot of the event with the spatializer showing?

Thank you


Unity Version 2023.2
Fmod Version 2.02.24

Unity Version 2023.2
Fmod Version 2.02.24

1 Like

Thank you for the information.

Unfortunately, I was not able to reproduce the issue with the following code:

using UnityEngine;

public class SetDistanceFromCode : MonoBehaviour
{
	private FMOD.Studio.EventDescription desc;
	private FMOD.Studio.EventInstance inst;
	public FMODUnity.EventReference eventRef;
	private FMOD.ChannelGroup channelGroup;
	public GameObject target;

    // Start is called before the first frame update
    void Start()
    {
        FMOD.RESULT result = FMODUnity.RuntimeManager.StudioSystem.getEvent(eventRef.Path, out desc);
		if (result != FMOD.RESULT.OK)
		{
			Debug.Log($"Could not find description with result {result}");
		}

		inst = FMODUnity.RuntimeManager.CreateInstance(eventRef);

		result = inst.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(target, target.GetComponent<Rigidbody>()));
	}

	// Update is called once per frame
	void Update()
	{
		if (Input.GetKeyDown(KeyCode.Escape))
		{
			Vector2 distances = new Vector2(35, 100);
			UserCode(desc, inst, true, distances, target);

			FMOD.RESULT result = inst.start();
			if (result != FMOD.RESULT.OK)
			{
				Debug.Log($"Could not start instance with result {result}");
			}
		}

		if (channelGroup.hasHandle())
		{
			channelGroup.get3DMinMaxDistance(out float min, out float max);
			Debug.Log($"Channel Min {min} Max {max}");
		}
		if (inst.isValid())
		{
			inst.getProperty(FMOD.Studio.EVENT_PROPERTY.MINIMUM_DISTANCE, out float min);
			inst.getProperty(FMOD.Studio.EVENT_PROPERTY.MAXIMUM_DISTANCE, out float max);
			Debug.Log($"Inst Min {min} Max {max}");
		}
	}

	private void UserCode(FMOD.Studio.EventDescription eventDescription, FMOD.Studio.EventInstance instance, bool is3D, Vector2 MinMaxDistance, GameObject target)
	{
		if (eventDescription.isValid())
		{

			if (instance.isValid() && is3D)
			{
				FMOD.RESULT result = instance.getChannelGroup(out channelGroup);
				if (result == FMOD.RESULT.OK)
				{
					//Debug.Log("Channel group successfully retrieved.");
					result = channelGroup.setMode(FMOD.MODE._3D | FMOD.MODE._3D_LINEARROLLOFF);
					if (result != FMOD.RESULT.OK)
					{
						Debug.Log($"Could not set mode with result {result}");
					}
					result = channelGroup.set3DMinMaxDistance(MinMaxDistance.x, MinMaxDistance.y);
					if (result != FMOD.RESULT.OK)
					{
						Debug.Log($"failed to set distances with result {result}");
					}
					else
					{
						Debug.Log("Set min max dist on CH");
					}
				}
				else
				{
					if (result != FMOD.RESULT.OK)
					{
						Debug.Log($"could not get CG with result {result}");
					}
				}

				{
					FMODUnity.RuntimeManager.AttachInstanceToGameObject(instance, target);
					result = instance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(target));
					if (result != FMOD.RESULT.OK)
					{
						Debug.Log($"could not set 3D attributes with result with result {result}");
					}
					else
					{
						Debug.Log("Set 3d attributes");
					}
				}

				result = instance.setProperty(FMOD.Studio.EVENT_PROPERTY.MINIMUM_DISTANCE, MinMaxDistance.x);
				if (result != FMOD.RESULT.OK)
				{
					Debug.Log($"Could not set instance min prop with result {result}");
				}
				else
				{
					Debug.Log("Set min distance");
				}
				result = instance.setProperty(FMOD.Studio.EVENT_PROPERTY.MAXIMUM_DISTANCE, MinMaxDistance.y);
				if (result != FMOD.RESULT.OK)
				{
					Debug.Log($"Could not set instance max pro with result {result}");
				}
				else
				{
					Debug.Log("Set max distance");
				}
			}
		}
	}
}

I have added some more logging and check. I see the following in the logs:


Would it be possible to add some more logging and share the full console log when trying to set the distances?

Thank you.

Let me provide an example that’s easy to understand.
First, build a sound event with a range of 1–50 in FMOD Studio.
Then, I’ll use the bank in Unity.

Using the code you provided, set both the min and max values to 1 and 100.
Move about 40 units away from the sound source and play the sound.
Since the range is 1–50, the sound seems to be heard normally.
However, as soon as you move to a distance of 80, the sound is no longer audible.

Next, set both the min and max values to 1000 and 1000.
Then move to a distance of about 40 units and play the sound.
Theoretically, the sound should be heard at 100% volume.
But in practice, the sound plays at only 10–20% of the intended volume.
It seems the 1–50 range of the sound is still being applied, while the min and max values are not being reflected at all.

The logs from your code are displayed correctly, but they are just logs.
You need to actually listen to the sound to confirm this.
Give it a try.

1 Like

The logs are displayed exactly the same as yours.
There’s absolutely no difference in the logs, as I’m using your code.


The sound event was built in FMOD Studio with a range of 1–50, as shown in the image I shared earlier.
Using the code you provided, I set the min and max values to 1000, 1000 to test the sound.
I manually pressed a key to play the sound.

The logs indicate that the values are set to 1000, 1000.
However, the sound attenuation behaves as if it is still based on the original 1–50 range, causing the sound to diminish accordingly.

Theoretically, if the min and max values are set to 1000, attenuation should not occur.
(Do you think the min value is too large? Even when setting the min value to 100, the sound attenuation functionality does not work as expected.)

Please test it again.

I’m also attaching the logs for reference.

1 Like

Are you investigating the cause?
Do you understand what the issue is?
Is it difficult to reproduce?

Thank you for the information and the video, it is very appreciated.

Apologies for the confusion. I think I have identified the issue.

We are trying to set the Event macro property: FMOD Studio | Event Macros Drawer Reference


However, we have the Distance Override enabled which means the effect values are being used rather than the event property values: FMOD Studio | Advanced Topics - The FMOD Spatializer Effect.

So we have two options:

  1. Disable the override values on the effect:
  2. Or set the values directly on the spatializer DSP:
private void UserCode(FMOD.Studio.EventDescription eventDescription, FMOD.Studio.EventInstance instance, bool is3D, Vector2 MinMaxDistance, GameObject target)
{
	if (eventDescription.isValid())
	{

		if (instance.isValid() && is3D)
		{
			FMOD.RESULT result = instance.getChannelGroup(out channelGroup);
			if (result == FMOD.RESULT.OK)
			{
				channelGroup.getNumDSPs(out int dsp);
				for (int i = 0; i < dsp; i++)
				{
					result = channelGroup.getDSP(i, out FMOD.DSP currDSP);
					if (result == FMOD.RESULT.OK)
					{
						result = currDSP.getType(out FMOD.DSP_TYPE type);
						if (result == FMOD.RESULT.OK)
						{
							if (type == FMOD.DSP_TYPE.PAN)
							{
								result = currDSP.setParameterFloat((int)FMOD.DSP_PAN._3D_MIN_DISTANCE, 1);
								if (result != FMOD.RESULT.OK)
								{
									Debug.Log($"Failed to set min distance with result {result}");
								}
								result = currDSP.setParameterFloat((int)FMOD.DSP_PAN._3D_MAX_DISTANCE, 100);
								if (result != FMOD.RESULT.OK)
								{
									Debug.Log($"Failed to set max distance with result {result}");
								}

								if (result == FMOD.RESULT.OK)
								{
									Debug.Log("Set min and max distances");
								}
							}
							else
							{
								Debug.Log($"Not DSP at index {i}");
							}
						}
						else
						{
							Debug.Log($"Failed to get type with result {result}");
						}
					}
					else
					{
						Debug.Log($"Failed to get DSP at index {i} with result {result}");
					}
				}
			}
			else
			{
				if (result != FMOD.RESULT.OK)
				{
					Debug.Log($"could not get CG with result {result}");
				}
			}
		}
	}
}

Please let me know if the issue persists.