Event MINIMUM_DISTANCE and MAXIMUM_DISTANCE returning -1 all the time

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.

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:

Is it related or I’m doing something wrong?

Thanks!

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.

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


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?

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.

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

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?

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. We are aware that the handling of min/max distance isn’t ideal and have plans to improve it for 2.2.

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

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

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.

Thanks for clarifying!
Looking forward for version 2.2 :slight_smile: