# Multiple instances of a custom plugin with FMOD Studio (...and API)

**URL:** <https://qa.fmod.com/t/multiple-instances-of-a-custom-plugin-with-fmod-studio-and-api/20344>\
**Category:** FMOD Engine\
**Created:** [June 23, 2023, 5:26am UTC](https://qa.fmod.com/t/multiple-instances-of-a-custom-plugin-with-fmod-studio-and-api/20344 "2023-06-23T05:26:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![peppemas72](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@peppemas72](https://qa.fmod.com/u/peppemas72)\
**Post date:** [June 23, 2023, 5:26am UTC](https://qa.fmod.com/t/multiple-instances-of-a-custom-plugin-with-fmod-studio-and-api/20344/1 "2023-06-23T05:26:14Z")

</div>

Greetings,

I have a very simple project with 2 events and each one contains a stream and an instance of my custom plugin.  
When I try to use the API I noticed that it always uses only 1 instance of the plugin.  
Is it possible to use an instance for each event?

This is the code I use to load the FMOD project using Studio API

```c++
result = FMOD::Studio::System::create(&m_system);
SucceededOrWarn("[FMOD] Cannot create System.", result);

result = m_system->getCoreSystem(&m_coreSystem);
SucceededOrWarn("[FMOD] Cannot get coreSystem", result);

result = m_coreSystem->setPluginPath("D:\\TEST\\Plugins");
SucceededOrWarn("[FMOD] Cannot set plugin path", result);

unsigned int pluginHandle;
result = m_coreSystem->loadPlugin("MyCustomPlugin", &pluginHandle, FMOD_PLUGINTYPE_DSP);
SucceededOrWarn("[FMOD] Cannot load the plugin", result);

result = m_coreSystem->setSoftwareFormat(0, FMOD_SPEAKERMODE_STEREO, 0);
SucceededOrWarn("[FMOD] Cannot set software format", result);

result = m_system->initialize(1024, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL, nullptr);
SucceededOrWarn("[FMOD] Cannot initialize system", result);

result = m_system->loadBankFile("D:\\TEST\\Master.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &m_masterBank);
SucceededOrWarn("[FMOD] Cannot load Master.bank", result);

result = m_system->loadBankFile("D:\\TEST\\Master.strings.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &m_stringsBank);
SucceededOrWarn("[FMOD] Cannot load Master.strings.bank", result);

result = m_system->getEvent("event:/dimmi_L", &m_eventDescriptionLeft);
SucceededOrWarn("[FMOD] Cannot get event dimmi_L.", result);

result = m_eventDescriptionLeft->createInstance(&m_eventInstanceLeft);
SucceededOrWarn("[FMOD] Cannot create event instance", result);

result = m_system->getEvent("event:/dimmi_R", &m_eventDescriptionRight);
SucceededOrWarn("[FMOD] Cannot get event dimmi_R.", result);

result = m_eventDescriptionRight->createInstance(&m_eventInstanceRight);
SucceededOrWarn("[FMOD] Cannot create event instance", result);

```

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [June 23, 2023, 6:43am UTC](https://qa.fmod.com/t/multiple-instances-of-a-custom-plugin-with-fmod-studio-and-api/20344/2 "2023-06-23T06:43:01Z")

</div>

Hi,

What version of FMOD are you using?

How are you accessing the plugin? I can see it being created but could I get a code snippet when you are trying to interact with it?

---

<div class="post-metadata">

**Author:** ![peppemas72](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@peppemas72](https://qa.fmod.com/u/peppemas72)\
**Post date:** [June 23, 2023, 7:46am UTC](https://qa.fmod.com/t/multiple-instances-of-a-custom-plugin-with-fmod-studio-and-api/20344/3 "2023-06-23T07:46:36Z")

</div>

Hi!

I’m using FMOD Studio 2.02.09 and FMOD Studio API 202113

Here the code on how I interact with the events:

```auto
       result = m_eventInstanceLeft->start();
       SucceededOrWarn("[FMOD] Cannot start event Left", result);

       result = m_eventInstanceRight->start();
       SucceededOrWarn("[FMOD] Cannot start event Right", result);
  
       // Position the listener at the origin
       m_attributes_left = {{ 0 }};
       m_attributes_left.forward.z = 1.0f;
       m_attributes_left.up.y = 1.0f;
       m_system->setListenerAttributes(0, &m_attributes_left);

       m_attributes_right = {{ 0 }};
       m_attributes_right.forward.z = 1.0f;
       m_attributes_right.up.y = 1.0f;

      .....
      .....
      .....

           // update left/right passing parameters to plugin
           m_attributes_left.position.x = float(x1);
           m_attributes_left.position.y = float(y1);
           m_attributes_left.position.z = float(z1);
           m_eventInstanceLeft->set3DAttributes(&m_attributes_left);
           
           m_attributes_right.position.x = float(x2);
           m_attributes_right.position.y = float(y2);
           m_attributes_right.position.z = float(z2);
           m_eventInstanceRight->set3DAttributes(&m_attributes_right);

```

Note that with the same code if I create a second copy of my plugin called “My Custom Plugin 2” (MyCustomPlugin2.dll) and assign it to the event:dimmi\_R in FMOD Studio and load at startup like this:

```auto
unsigned int pluginHandle;
result = m_coreSystem->loadPlugin("MyCustomPlugin", &pluginHandle, FMOD_PLUGINTYPE_DSP);
SucceededOrWarn("[FMOD] Cannot load the plugin", result);

unsigned int pluginHandle2;
result = m_coreSystem->loadPlugin("MyCustomPlugin2", &pluginHandle2, FMOD_PLUGINTYPE_DSP);
SucceededOrWarn("[FMOD] Cannot load the plugin 2", result);

```

It works perfectly. Could be a problem on the plugin itself ? Is there an option when the plugin is  
created to specify that must be instanced more than once ?

Thank you for your support.  
Giuseppe

---

<div class="post-metadata">

**Author:** ![peppemas72](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@peppemas72](https://qa.fmod.com/u/peppemas72)\
**Post date:** [June 24, 2023, 11:39am UTC](https://qa.fmod.com/t/multiple-instances-of-a-custom-plugin-with-fmod-studio-and-api/20344/4 "2023-06-24T11:39:25Z")

</div>

Hello,

I solved the problem with my plugin.  
Instead of initialize global variables on event sys\_register I moved everything in a class and initialized each time the CREATE event is called.

thank you  
Giuseppe

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [June 25, 2023, 11:14pm UTC](https://qa.fmod.com/t/multiple-instances-of-a-custom-plugin-with-fmod-studio-and-api/20344/5 "2023-06-25T23:14:29Z")

</div>

Hi.

Thank you for sharing the solution.
