Automating audio file import and assignment to event instruments via scripting API

Hello team FMOD!
The game I’m currently working on has a lot of characters that share a similar setup for their sound events. I’m writing a script to automate the import process. Here’s what I’m trying to achieve:

  • Using currently selected audio assets in FMOD Studio (working).
  • Grouping files with the same prefix (differing only in variation numbers) (working).
  • Creating events with a track that contains a multi-instrument for each group (working).
  • Adding volume and pitch modulators to the multi-instrument (working).
  • Placing events in the correct folder structure - (not working yet).
  • Setting the length of the created multi-instrument to the length of the contained assets (not working yet).
  • Assigning the created event to a bank that corresponds to the character name (not working yet).

I got quite a lot working already, but I’m having trouble with the last three parts (properly assigning an event folder to the newly created event, adding it to a bank and setting the length of the created multi-instrument to the length of its content, like the corresponding context menu item).

I manage to put the event in the events master folder, using this code:

       var myEvent = studio.project.create("Event");
        myEvent.name = eventName;
        // Set the events folder to the root event folder.
        myEvent.folder = studio.project.workspace.masterEventFolder;

For the bank assignment and resizing the multi-instrument I haven’t managed to get anything working yet.

Could you point me in the right direction as to which functions to use for these tasks?

If it helps, I’m happy to share the script I’ve created so far!

1 Like

Hi,

You can find all the EventFolder’s in your project with:

var folders = studio.project.model.EventFolder.findInstances()
folders.forEach(function(folder) { console.log(folder.name) } )

You can then find the folder you are looking for with something like:

folders.forEach(function(folder) {
if (folder.name == "The folder I want")
    myEvent.folder = folder;
})

I previously made a script for creating an event with an multi instrument on a button press:
Create3DMultiEventMacro.js.txt (1.9 KB). Specifically for setting the length you would use:

track.addSound(event.timeline, 'MultiSound', 0, /*Set length here*/)

To assign an event to a bank you add it to the relationships (FMOD Studio | Scripting API Reference - Project.ManagedObject)

var myEvent = studio.window.browserCurrent()
undefined
var bank = studio.window.browserCurrent()
undefined
myEvent.relationships.banks.add(bank)
true

Hope this helps!

1 Like

Thanks so much Connor!

That was the missing piece, now it’s all working.

After browsing the forum a bit more I also managed to add FX presets to my master track chain and some modulators to the created multi instrument.

Happy days!

1 Like

Great to hear it worked!

If you have any more questions please do not hesitate to ask!