# Event MINIMUM\_DISTANCE and MAXIMUM\_DISTANCE returning -1 all the time

**URL:** https://qa.fmod.com/t/event-minimum-distance-and-maximum-distance-returning-1-all-the-time/15882
**Category:** Unity
**Tags:** unity, csharp
**Created:** [June 13, 2020, 7:30am UTC](https://qa.fmod.com/t/event-minimum-distance-and-maximum-distance-returning-1-all-the-time/15882 "2020-06-13T07:30:14Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Bokus](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bokus](https://qa.fmod.com/u/Bokus)
#### Post date: [June 13, 2020, 7:30am UTC](https://qa.fmod.com/t/event-minimum-distance-and-maximum-distance-returning-1-all-the-time/15882/1 "2020-06-13T07:30:14Z")

</div>

Hello,

I’m trying to get 3D event min and max distance in Unity 2019.3.15f1.  
I used FMOD Studio 2.00.09 example project with this code.

```auto
void Start()
{
    FMOD.Studio.EventInstance gun = FMODUnity.RuntimeManager.CreateInstance("event:/Weapons/Machine Gun");
    FMODUnity.RuntimeManager.AttachInstanceToGameObject(gun, transform, GetComponent<Rigidbody>());
    gun.getProperty(FMOD.Studio.EVENT_PROPERTY.MINIMUM_DISTANCE, out float minDist);
    print(minDist);
    gun.getProperty(FMOD.Studio.EVENT_PROPERTY.MAXIMUM_DISTANCE, out float maxDist);
    print(maxDist);
    gun.start();
    gun.release();
}

```

And I’m getting value -1 for both.  
I found a similar post some time ago with the previous version:

> [@Issue with FMOD\_STUDIO\_EVENT\_PROPERTY\_MINIMUM\_DISTANCE / FMOD\_STUDIO\_EVENT\_PROPERTY\_MAXIMUM\_DISTANCE?](https://qa.fmod.com/t/issue-with-fmod-studio-event-property-minimum-distance-fmod-studio-event-property-maximum-distance/12297):
>
> It’s fantastic to be able to override the min/max distance per instance using the FMOD Studio API. However, a value of -1 (for default) does not seem to be working as expected. I assume that -1 implies that the settings from the event editor are used, but when I set this, I don’t hear anything anymore (ends up with a size of 0?). Is this behavior as expected?

Is it related or I’m doing something wrong?

Thanks!

---

<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: [June 14, 2020, 10:47pm UTC](https://qa.fmod.com/t/event-minimum-distance-and-maximum-distance-returning-1-all-the-time/15882/2 "2020-06-14T22:47:27Z")

</div>

When you call getProperty on the EventInstance you are getting back the value you set (or the default). In this case that value is -1, meaning use the values from the Event data. To fetch the min / max distance authored in FMOD Studio you can use [EventDescription::getMaximumDistance](https://fmod.com/resources/documentation-api?version=2.0&page=studio-api-eventdescription.html#studio_eventdescription_getmaximumdistance).

---

<div class="post-metadata">

### Author: ![Bokus](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bokus](https://qa.fmod.com/u/Bokus)
#### Post date: [June 15, 2020, 5:31pm UTC](https://qa.fmod.com/t/event-minimum-distance-and-maximum-distance-returning-1-all-the-time/15882/3 "2020-06-15T17:31:04Z")

</div>

Hi Mathew,

getMaximumDistance indeed works. I was expecting I’ll be able to get value from the instance cause instance will change depending on parameters.  
I’m trying to implement footstep system where other than walking I have sprint and sneak options.  
Here is my setup

 ![FMOD Studio footsteps](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/6/6ef42e649875f65d37cace7773d4e05453ba0074.png)  
So by changing Speed param I’m getting different volumes.  
What doesn’t seem to work is when I added Spatializer override, cause max distance is still default 20m from Master track and not the one I’m setting by params. And if I remove Master Spatializer then I get 0 for max distance.

Is this doable or I need to take different approach?

---

<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: [June 17, 2020, 1:31am UTC](https://qa.fmod.com/t/event-minimum-distance-and-maximum-distance-returning-1-all-the-time/15882/4 "2020-06-17T01:31:36Z")

</div>

If you plan on using the override feature within Unity your query logic will be slightly more complicated. First call getProperty on the instance, if it returns -1 then call getMaximumDistance on the description, otherwise use the instance value. If you remove the spatializer then that event will have no min/max distance.

---

<div class="post-metadata">

### Author: ![Bokus](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bokus](https://qa.fmod.com/u/Bokus)
#### Post date: [July 15, 2020, 2:06pm UTC](https://qa.fmod.com/t/event-minimum-distance-and-maximum-distance-returning-1-all-the-time/15882/5 "2020-07-15T14:06:12Z")

</div>

Hi Mathew,

Sorry for the late reply, I finally managed to try this out.  
I’m not sure if this is how you meant to try it out but it didn’t work for me. This is the method I’m using:

```
void PlayFootstep(int surfaceType, int speed = 0)
{
    FMOD.Studio.EventInstance Footstep = FMODUnity.RuntimeManager.CreateInstance("event:/SFX/Footsteps/Footsteps");        
    FMODUnity.RuntimeManager.AttachInstanceToGameObject(Footstep, transform, GetComponent<Rigidbody>());
    
    Footstep.setParameterByName(ResourceManager.Instance.references.fMODParameters.fmodParameterSurface, surfaceType);
    Footstep.setParameterByName(ResourceManager.Instance.references.fMODParameters.fmodParameterSpeed, speed);

    Footstep.getProperty(FMOD.Studio.EVENT_PROPERTY.MAXIMUM_DISTANCE, out float maxDist);
    print(maxDist);
    if (maxDist < 0)
    {
        FMODUnity.RuntimeManager.GetEventDescription("event:/SFX/Footsteps/Footsteps").getMaximumDistance(out float newMaxDist);
        print(newMaxDist);
    }
    
    Footstep.start();                                                                                        
    Footstep.release();                                                                                      
}

```

When I pass speed 1 for a Sneak, I would expect that max distance to be 6 and not default 20, but at first I get printed -1 for maxDist and then 20 for newMaxDist, so it’s not picking up overridden value.

This is how it’s set in FMOD Studio

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/6/6e774b7ad808282a447b29fab1ed42a294a2053a.png)

So as you can see I have overridden max distance for Sneak, but it’s not picking it up in the code.  
Am I doing this correctly?

---

<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, 2:08am UTC](https://qa.fmod.com/t/event-minimum-distance-and-maximum-distance-returning-1-all-the-time/15882/6 "2020-07-16T02:08:23Z")

</div>

It looks like you have a spatializer on a track that isn’t the master track. The query API cannot see the values of these effects. For details please check the query API [documentation](https://fmod.com/resources/documentation-api?version=2.1&page=studio-api-eventdescription.html#studio_eventdescription_getmaximumdistance). We are aware that the handling of min/max distance isn’t ideal and have plans to improve it for 2.2.

---

<div class="post-metadata">

### Author: ![Bokus](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bokus](https://qa.fmod.com/u/Bokus)
#### Post date: [July 16, 2020, 8:41am UTC](https://qa.fmod.com/t/event-minimum-distance-and-maximum-distance-returning-1-all-the-time/15882/7 "2020-07-16T08:41:33Z")

</div>

Ok, I see.  
I have the Master track defined too.  
I just hoped that my override on other tracks will work 🙂

So in v2.2 you plan to add support for overriding max/min distance in some way?

---

<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, 1:12am UTC](https://qa.fmod.com/t/event-minimum-distance-and-maximum-distance-returning-1-all-the-time/15882/8 "2020-07-17T01:12:53Z")

</div>

Unfortunately they won’t, only the master track is considered for min/max override and the query APIs.

In 2.2 we will be making min/max a property of the Event rather than a property of a specific panner effect. This means any panner within the event including those on tracks will respond to the min/max Event value. Additionally we will be making min/max at the Event level automatable, so you can expose parameters to control the range just like any other Event property.

---

<div class="post-metadata">

### Author: ![Bokus](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bokus](https://qa.fmod.com/u/Bokus)
#### Post date: [July 17, 2020, 9:16am UTC](https://qa.fmod.com/t/event-minimum-distance-and-maximum-distance-returning-1-all-the-time/15882/9 "2020-07-17T09:16:44Z")

</div>

Thanks for clarifying!  
Looking forward for version 2.2 🙂

---

<div class="post-metadata">

### Author: ![LucaPiccina](https://avatars.discourse-cdn.com/v4/letter/l/7feea3/32.png) [@LucaPiccina](https://qa.fmod.com/u/LucaPiccina)
#### Post date: [September 22, 2021, 2:53pm UTC](https://qa.fmod.com/t/event-minimum-distance-and-maximum-distance-returning-1-all-the-time/15882/10 "2021-09-22T14:53:34Z")

</div>

Hi Mathew,  
I resume this old thread since I’ve also some doubts about setting the min\maxdist through Event Instance Property (can’t use Fmod 2.02 at the moment).  
I also get (for example, for min dist using EventInstance-\>getpropertyt): -1 as minDist value, then I set the minimum distance to let’s say 50 with setProperty, and then I verify that the mindist is effectively changed with the same getProperty (and this time I get 50, as expected).  
The problem is that inside the game apparently there is no change in audio even with extreme values…so I am wondering…does this setProperty work also with presets? because I’ve got a spatializer on the main track but it’s a preset shared between multiple events…so maybe no error is logged but the value is not set because it’s a preset?

Thank you very much

P.S: I am using Fmod 2.01 with a proprietary engine…

---

<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: [September 22, 2021, 11:08pm UTC](https://qa.fmod.com/t/event-minimum-distance-and-maximum-distance-returning-1-all-the-time/15882/11 "2021-09-22T23:08:32Z")

</div>

The key things with 2.01 are only 3D spatializers on the master track are affected by setProperty min / max. Whether that effect is applied directly or via a preset to the Event shouldn’t make any difference. If you min distance is larger than your max distance you might get some weird results, but otherwise it should apply.

Can you perform a simple test setting the min distance to 1000, then placing the Event 900 units away, it should still be fully audible.
