Change Convolution Reverb's IR via script


(Matze Kramer) #1

Hi!
I feel kinda stupid asking this question, but: How do I launch an FMOD Script at runtime, from within FMOD or, even better, from Unity?
I’d like to change Impulse Responses on my single instance of convolution reverb using ConvolutionReverb.setIRFromFilePath(filePath) - there will be due loading time and silence between rooms.

I’m thinking of a script called ChangeIR.js or so. Whenever Unity calls this script it passes a variable that holds the room index (about 20 rooms) and the script will do something like (syntax omitted):


if RoomIndex = 2
ConvolutionReverb.setIRFromFilePath(tiled_room.wav)

Is this going to work or am I on an entirely wrong path?

Thanks,
Matt


(Matze Kramer) #2

Let me refine this:

How do I, in general, launch a script at runtime without hitting ‘Scripts/Reload’ or from some type of console, but from within the Game?

Would it be possible to “attach” a js script (which lives in my project’s ‘/Scripts’ folder) to a mixer snapshot, i.e. have the snapshot launch the script as soon as it’s playing? I did dump() all info on the snapshot in the terminal but most of the parameters aren’t covered in the documentation, I spent a day taking guesses and experimenting (to no success) and there’s virtually not a single tutorial out there.

Halp anyone?

Alternatively, is there a way to have a script launch at startup and loop in the background? When I put a while loop in my script, have it count to 100, log the current number and wait 100ms every iteration, FMOD (on Mac) will give me the beach ball for 10 seconds (that’s how long the script takes) and only then log 100 lines at once. Accordingly, it will just beach ball and crash if I put an infinite loop. Looks to me like the script is happening in the main thread - could that be the problem?

It’s funny how nobody seems to be using scripts in FMOD that much, or am I missing something?


(Joseph Harvey) #3

FMOD Studio scripts are only effective within the FMOD Studio application, and cannot be used in-game. (Well, not without using live update, but I assume you don’t want the FMOD Studio GUI running in the background whenever your game is running.) This is because the scripting feature is designed to allow you to simplify your workflow by replacing time-intensive multi-step procedures with keyboard shortcuts and menu commands. It is not designed to allow you to trigger and control the content of your project, as the FMOD Studio API already exists for that purpose.

For the same reason, it is not possible to trigger an FMOD Studio script from an event or snapshot, as such a trigger would be meaningless in-game.

In addition, it is not possible to replace the impulse response used by a convolution reverb effect as your game runs. This is because the impulse response file is built into your project’s master bank as part of the bank building process. A better option is to create multiple different convolution effects on different return buses, and use snapshots to determine which of those buses receives audible input.