Automating creating Event Instruments via scripting

I’m trying to create EventInstruments via scripting. I actually need sub - sub events. I couldn’t find details in the documentation, but after trying it out and guessing a few parameters I seem to be able to generate them. I’m doing it like this;

var _instrumentTrack = partEvent.addGroupTrack( _instrument );
var instrumentEventTrack = _instrumentTrack.addSound(partEvent.timeline, "EventSound", _start, _timelength);

The docs at
https://fmod.com/docs/2.02/studio/scripting-api-reference-project-model-track.html#grouptrackaddsound
say I should only add “model.Sound / model.SingleSound / model.MultiSound / model.ProgrammerSound”
I’m using model.EventSound…
After my script runs the project crashes within a few seconds, I’m sure I’m missing some relationships or other data.

I’m attaching my full project build script - which takes a set of audio assets and sets up the project based on the folders and file naming like this:
{mainevent} / {subevent} / {trackname}_{tracknum}.wav
I have 4 main events, 8 subevents and 5 tracks on each of those (so around 160 sounds) I have a lot of these to setup and want to automate as much of this as possible.

thanks for any thoughts or help!

BuildTracks.js.txt (4.9 KB)

Hi,

Your usage of addSound() to create event instruments is correct.

The reason Studio is crashing is due to the following line:

_instrumentTrack.mixerGroup.output = newEvent.mixer.masterBus;

In this case, you’re assigning the output of mixerGroup from a child event to the master track of an separate event, which in this case is the parent event. When you select the child event or attempt to play it (potentially via playing the parent event), Studio gets an invalid mixerGroup from the child event due to the reroute, and crashes.

Attempting to reroute an event in this way is unintended, and should be flagged by Studio’s validation process as an issue with the project - I’ve passed the fact that it doesn’t along to the development team for further investigation. Regardless, you should be able to avoid the crash by removing that line from your script.

1 Like