# Script to register child events in MultiSound?

**URL:** <https://qa.fmod.com/t/script-to-register-child-events-in-multisound/21492>\
**Category:** FMOD Studio\
**Tags:** javascript\
**Created:** [April 12, 2024, 12:52pm UTC](https://qa.fmod.com/t/script-to-register-child-events-in-multisound/21492 "2024-04-12T12:52:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![berserk77](https://avatars.discourse-cdn.com/v4/letter/b/7ba0ec/32.png) [@berserk77](https://qa.fmod.com/u/berserk77)\
**Post date:** [April 12, 2024, 12:52pm UTC](https://qa.fmod.com/t/script-to-register-child-events-in-multisound/21492/1 "2024-04-12T12:52:24Z")

</div>

on selected events  
Add multi-sound,  
add a child event,  
Add programmer sound to child event  
I would like to register a child event for the added multi-sound.  
I tried a few things but failed.

```auto
var event = studio.window.browserSelection()[0];
var track = event.addGroupTrack("audio 1");
var multiInstrument = track.addSound(event.timeline, 'MultiSound', 0, 10);

var childEvent = studio.project.create("Event");
childEvent.name = 'voc1';
childEvent.folder = event;

var childtrack = childEvent.addGroupTrack("Audio 1");

var programInstrument = childtrack.addSound(childEvent.timeline, 'ProgrammerSound', 0, 10);
programInstrument.name = "ProgrammerSound test";

//programInstrument.owner = multiInstrument; <- fail
//multiInstrument.sounds.push(childEvent); <- fail
//multiInstrument.sounds.push(programInstrument); <- fail

```

---

<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:** [April 17, 2024, 3:15am UTC](https://qa.fmod.com/t/script-to-register-child-events-in-multisound/21492/2 "2024-04-17T03:15:19Z")

</div>

> [@berserk77](#):
>
> ```auto
> //programInstrument.owner = multiInstrument;
> //...
> //multiInstrument.sounds.push(programInstrument);
> 
> ```

These fail because the programmer instrument belongs to the `childEvent.timeline` already. You’ll want to create the instrument independently of the timeline, and _then_ add it to the multi instrument, like so:

```auto
var programmerInstrument = studio.project.create('ProgrammerSound');
programmerInstrument.owner = multiInstrument;
// or
multiInstrument.relationships.sounds.add(programmerInstrument);

```

> [@berserk77](#):
>
> `//multiInstrument.sounds.push(childEvent);`

This fails because `childEvent` isn’t actually an instrument/`sound`, it’s an event. You’ll need to do create an event instrument, assign the child event to it, then add it to the multi instrument:

```auto
var eventInstrument = studio.project.create('EventSound');
eventInstrument.event = childEvent;
eventInstrument.owner = multiInstrument;
// or
multiInstrument.relationships.sounds.add(eventInstrument);

```

---

<div class="post-metadata">

**Author:** ![berserk77](https://avatars.discourse-cdn.com/v4/letter/b/7ba0ec/32.png) [@berserk77](https://qa.fmod.com/u/berserk77)\
**Post date:** [April 17, 2024, 6:43am UTC](https://qa.fmod.com/t/script-to-register-child-events-in-multisound/21492/3 "2024-04-17T06:43:32Z")

</div>

Using the code below means,  
`multiInstrument.relationships.sounds.add(programInstrument);`

This error occurs.  
15:35:02 [script-error] An error in the callback “onClicked”: Error: Cannot modify relationship ‘sounds’ as the objects belong to different files., callstack:

I want to insert the child event’s programmer’s instrument into the parent’s multi-instrument.

 ![multi_to_program](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/0/08c9b1b1491fe1e6d4c91a98c40800e68889c4f4.jpeg)

---

<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:** [April 18, 2024, 5:33am UTC](https://qa.fmod.com/t/script-to-register-child-events-in-multisound/21492/4 "2024-04-18T05:33:12Z")

</div>

> [@berserk77](#):
>
> I want to insert the child event’s programmer’s instrument into the parent’s multi-instrument.

Just to be clear, are you trying to transfer ownership of the programmer instrument from the child “voc1” event to the parent “attack” event? Or are you trying to have child event retain ownership while _also_ having the programming instrument as an item in the multi instrument?

---

<div class="post-metadata">

**Author:** ![berserk77](https://avatars.discourse-cdn.com/v4/letter/b/7ba0ec/32.png) [@berserk77](https://qa.fmod.com/u/berserk77)\
**Post date:** [May 22, 2024, 9:24am UTC](https://qa.fmod.com/t/script-to-register-child-events-in-multisound/21492/5 "2024-05-22T09:24:12Z")

</div>

I would like to maintain ownership and place the programming instrument within the multi-instrument.

 ![result](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/9/956abb9a2bc295bc3177b13ad34bec889521e7b9.jpeg)

---

<div class="post-metadata">

**Author:** ![berserk77](https://avatars.discourse-cdn.com/v4/letter/b/7ba0ec/32.png) [@berserk77](https://qa.fmod.com/u/berserk77)\
**Post date:** [May 22, 2024, 9:40am UTC](https://qa.fmod.com/t/script-to-register-child-events-in-multisound/21492/6 "2024-05-22T09:40:11Z")

</div>

![result_2](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/c/c2d52a9306b570c3d564f47e3e25565c0f8bd894.jpeg)  
To be precise, child tracks are registered under multi instrument.

---

<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:** [May 23, 2024, 6:03am UTC](https://qa.fmod.com/t/script-to-register-child-events-in-multisound/21492/7 "2024-05-23T06:03:28Z")

</div>

> [@berserk77](#):
>
> I would like to maintain ownership and place the programming instrument within the multi-instrument.

Unfortunately, it’s not possible to place an instrument belonging to another event in a multi-instrument’s playlist. An instrument can only belong to a single thing at once.

What audio behavior are you trying to accomplish by placing an existing programmer instrument in the multi-instrument’s playlist? With more detail, I may be able to suggest an alternative way to implement the desired behavior.

---

<div class="post-metadata">

**Author:** ![berserk77](https://avatars.discourse-cdn.com/v4/letter/b/7ba0ec/32.png) [@berserk77](https://qa.fmod.com/u/berserk77)\
**Post date:** [May 23, 2024, 6:07am UTC](https://qa.fmod.com/t/script-to-register-child-events-in-multisound/21492/8 "2024-05-23T06:07:36Z")

</div>

If you drag it directly, it will be registered. Is it not supported in the script?

---

<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:** [May 23, 2024, 6:23am UTC](https://qa.fmod.com/t/script-to-register-child-events-in-multisound/21492/9 "2024-05-23T06:23:05Z")

</div>

Dragging directly into a multi-instrument cannot be done with programmer instruments. However, it can be done with events like “voc1” - dragging “voc1” into the multi-instrument will create an event instrument that plays the “voc1” event.

Below, I’ve modified your original code snippet to do what you seem to want - it will create an event “voc1”, add “voc1” to an event instrument, and add the event instrument to a multi-instrument:

```js
var event = studio.window.browserSelection()[0];
var track = event.addGroupTrack("audio 1");
var multiInstrument = track.addSound(event.timeline, 'MultiSound', 0, 10);

var childEvent = studio.project.create("Event");
childEvent.name = 'voc1';
childEvent.folder = event;

var eventInstrument = studio.project.create('EventSound');
eventInstrument.event = childEvent;
eventInstrument.owner = multiInstrument;

```
