# Adding a Prefader Shared Effect via script

**URL:** <https://qa.fmod.com/t/adding-a-prefader-shared-effect-via-script/22319>\
**Category:** FMOD Studio\
**Created:** [November 18, 2024, 6:46pm UTC](https://qa.fmod.com/t/adding-a-prefader-shared-effect-via-script/22319 "2024-11-18T18:46:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![roc\_lee](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@roc\_lee](https://qa.fmod.com/u/roc_lee)\
**Post date:** [November 18, 2024, 6:46pm UTC](https://qa.fmod.com/t/adding-a-prefader-shared-effect-via-script/22319/1 "2024-11-18T18:46:52Z")

</div>

Trying to add a Shared Effect before the fader to a series of events via script, I found this [old thread](https://qa.fmod.com/t/scripting-how-to-add-effect-before-volume-change-output-of-return-and-create-parameter/13841) that shares how to add an effect using relationships.insert() on the effects array, however that function will not take an effects chain as an input. Is this a bug? Using FMOD Studio 2.03

here’s an example just using the console to grab an effect chain and an event:

> effect = studio.window.browserCurrent()  
> (ManagedObject:EffectPreset)  
> e = studio.window.browserCurrent()  
> (ManagedObject:Event)  
> e.masterTrack.mixerGroup.effectChain.relationships.effects.insert(0, effect)
> 
> Error: Relationship ‘effects’ expects a destination of entity type ‘MixerEffect’.

---

<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:** [November 20, 2024, 4:49am UTC](https://qa.fmod.com/t/adding-a-prefader-shared-effect-via-script/22319/2 "2024-11-20T04:49:54Z")

</div>

Due to the abstraction that Shared Effects make use of to be shared, `EffectPreset` can’t just be added to the effect chain. The effect itself needs to be created first, which will create a `ManagedObject:ProxyEffect`.

Following the snippet you posted, the simplest way to do this at present is to do the following:

```javascript
// Get ManagedObject:EffectPreset from studio.window
var effect = studio.window.browserCurrent();
// Get ManagedObject:Event from studio.window
var e = studio.window.browserCurrent();

// Create ProxyEffect from EffectPreset and insert into effect chain
var proxyEffect = e.masterTrack.mixerGroup.effectChain.addEffect(effect)

// Move new ProxyEffect to be the first effect in the chain
var totalFX = proxyEffect.owner.relationships.effects.destinations.length;
proxyEffect.owner.relationships.effects.insert(0, proxyEffect.owner.relationships.effects.destinations[totalFX - 1]);

```

This is definitely not an ideal way to go about it, and addEffect() should have an overload that allows for you to specify the index that the effect is inserted at - I’ve added this to our internal feature/improvement tracker.

---

<div class="post-metadata">

**Author:** ![roc\_lee](https://avatars.discourse-cdn.com/v4/letter/r/bc79bd/32.png) [@roc\_lee](https://qa.fmod.com/u/roc_lee)\
**Post date:** [November 21, 2024, 3:37am UTC](https://qa.fmod.com/t/adding-a-prefader-shared-effect-via-script/22319/3 "2024-11-21T03:37:25Z")

</div>

Awesome this works great, thanks!

Will also work directly referencing the effectChain directly from the event:

```auto
e.masterTrack.mixerGroup.effectChain.relationships.effects.insert(0, proxyEffect)

```
