Update global distance min/max variable from code?

I’m working on a top down game where you can zoom the camera in and out. I want to explore changing the min distance for all the spatializers when you zoom out so sound effects that occur on the camera all sound about the same and when you zoom in the sound effects outside the camera would become quieter.

Ideally I’d like to call some API to change global min/max distance so that I can achieve this idea. I’ve been digging around but haven’t found an answer. How would I go about trying to make this happen?

I have found this in the API docs which seems to get me pretty close:


And it looks like I can loop through all loaded banks and all events to get the instances that are playing:

I’m going to set that up for now but still holding out that there’s a simpler solution. Would love to hear a response if there is :slight_smile:


That is a good way to get all events that are currently playing. Then when you are ready to change the distances you could use something like this:

currentInstance.setProperty(FMOD.Studio.EVENT_PROPERTY.MINIMUM_DISTANCE, NewValue);

Use the same function but change MINMUM_DITANCE to MAXIMUM_DISTANCE.

Hope this helps!

Is this the best way to approach this (change the min/max distance for every event)? I wanted to make sure there wasn’t a one place spot I could be doing this or if it is just every active event.

I only need to set the min/max distance every once in awhile (when the camera zoom level changes) but this tactic appears to have the downside that new sound effects will play with the default min/max (which makes sense as I iterate through all the existing event instances to set the values).

I can every single frame go through and set the min max but this seems like a slight shame. So I guess I’m still trying to discover if there’s a cleaner/nicer way to accomplish what I’m trying to accomplish.

Instead of only changing active events you could just change every event. That way when a new event starts its values will already be set. Or when an event starts you could check what the global values are and set it accordingly before it makes noise. There are a few options.

How do I access every event? I’ve been iterating through all event descriptions from a particular bank and then iterating through all event instances to set the min/max distance. This appears to only impact active events (I think) or at the very least new events don’t have the min/max distance set.

Here’s what I’m doing:

int descCount = _cachedBankDescriptions.Length;

for (int i = 0; i < descCount; i++)
    EventDescription desc = _cachedBankDescriptions[i];

    CheckResult(desc.getInstanceList(_eventInstances)); // Just a custom version that does not generate garbage

    int instanceCount = _eventInstances.Count;

    for (int j = 0; j < instanceCount; j++)
        EventInstance ev = _eventInstances[j];
        CheckResult(ev.setProperty(EVENT_PROPERTY.MINIMUM_DISTANCE, _currentMin));
        CheckResult(ev.setProperty(EVENT_PROPERTY.MAXIMUM_DISTANCE, _currentMax));

EDIT Ok I see the call back on description and can leverage that. But I don’t see how to change every event instead of just active events.

Apologies, you can only access active events. My mistake.

Your current method is the best I can think of. When the camera changes position loop through all the events, then when an event is started assign it to the global values.

Sorry for the confusion.

Thanks for all the help. Here’s fully what I ended up doing (for the solution)

When the min/max needs to change I will loop over all active events from the event description and set their min/max using setProperty.

I also attach to the event description’s callback during initialization and listen for the event for new events being created. I will then set their min/max to the current values.

1 Like

Thank you for sharing the solution!

Hey folks. Surely you can just use a global parameter and automate the min/max distance values on every event’s master macro controls (within fmod)??? No code required… (except for driving the Global Param with the zoom distance)

You can even do this on a preset spatialiser effect with distance override turned on, if you don’t want to worry about having to mess with lots of batch editing later on…

1 Like

@Damion1 That’s a nice solution (and what I was poking for to see if there was a better way of doing it).


1 Like