# Automating creating Event Instruments via scripting

**URL:** https://qa.fmod.com/t/automating-creating-event-instruments-via-scripting/21734
**Category:** FMOD Studio
**Created:** [June 7, 2024, 2:58pm UTC](https://qa.fmod.com/t/automating-creating-event-instruments-via-scripting/21734 "2024-06-07T14:58:32Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![spakment](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@spakment](https://qa.fmod.com/u/spakment)
#### Post date: [June 7, 2024, 2:58pm UTC](https://qa.fmod.com/t/automating-creating-event-instruments-via-scripting/21734/1 "2024-06-07T14:58:33Z")

</div>

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;

```auto
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](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](https://qa.fmod.com/uploads/short-url/rAnOzjCTT15LQqpHhIPTRX0LXL5.txt) (4.9 KB)

---

<div class="post-metadata">

### Author: ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)
#### Post date: [June 13, 2024, 3:26am UTC](https://qa.fmod.com/t/automating-creating-event-instruments-via-scripting/21734/2 "2024-06-13T03:26:21Z")

</div>

Hi,

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

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

```auto
_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.
