# Change Event Instance Parameter from another script

**URL:** <https://qa.fmod.com/t/change-event-instance-parameter-from-another-script/23151>\
**Category:** Unity\
**Tags:** unity, csharp\
**Created:** [July 11, 2025, 10:23pm UTC](https://qa.fmod.com/t/change-event-instance-parameter-from-another-script/23151 "2025-07-11T22:23:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![EpicMcDude](https://avatars.discourse-cdn.com/v4/letter/e/d6d6ee/32.png) [@EpicMcDude](https://qa.fmod.com/u/EpicMcDude)\
**Post date:** [July 11, 2025, 10:23pm UTC](https://qa.fmod.com/t/change-event-instance-parameter-from-another-script/23151/1 "2025-07-11T22:23:30Z")

</div>

Hi,

Trying to change a parameter value from an Event Instance created on another script, it seems that just providing the event path and setParameterByName doesn’t work. Is there a step I’m missing?

> public override void OnEnter()  
> {  
> if (FMODEvent.Value == null || ParameterName.Value == null)  
> {  
> return;  
> }
> 
> ```
> var go = Fsm.GetOwnerDefaultTarget(GameObject);
> 
> Instance = RuntimeManager.CreateInstance(FMODEvent.Value);
> RuntimeManager.AttachInstanceToGameObject(Instance, go.transform);
> 
> if (!EveryFrame)
> {
> Instance.setParameterByName(ParameterName.Value, ParameterValue.Value);
> Finish();
> }
> 
> ```
> 
> }

---

<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:** [July 14, 2025, 12:07am UTC](https://qa.fmod.com/t/change-event-instance-parameter-from-another-script/23151/2 "2025-07-14T00:07:12Z")

</div>

Hi,

The issue is we are setting the parameter on an new instance on the one currently playing. We need to try a retrieve the one that was played via the other script.

If you know the path of the event etc: `event:/Music/Level 01` we could use [FMOD Engine | Studio Api System - Studio::System::Getevent](https://fmod.com/docs/2.02/api/studio-api-system.html#studio_system_getevent) to retrieve the [FMOD Engine | Studio Api Eventdescription](https://fmod.com/docs/2.02/api/studio-api-eventdescription.html) which we can use to get a list of all the created event instances: [FMOD Engine | Studio Api Eventdescription - Studio::Eventdescription::Getinstancelist](https://fmod.com/docs/2.02/api/studio-api-eventdescription.html#studio_eventdescription_getinstancelist). This would then allow you to set the parameter on those instances. It would look something like this:

```auto
FMOD.RESULT result = FMODUnity.RuntimeManager.StudioSystem.getEvent(FMODEventPath, out FMOD.Studio.EventDescription eventDescription);

result = eventDescription.getInstanceCount(out int instanceCount);
FMOD.Studio.EventInstance[] instances = new FMOD.Studio.EventInstance[instanceCount];
result = eventDescription.getInstanceList(out instances);

foreach (FMOD.Studio.EventInstance currEvent in instances)
{
    result = currEvent.setParameterByName(ParameterName, ParameterValue);
}

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![EpicMcDude](https://avatars.discourse-cdn.com/v4/letter/e/d6d6ee/32.png) [@EpicMcDude](https://qa.fmod.com/u/EpicMcDude)\
**Post date:** [July 14, 2025, 8:43pm UTC](https://qa.fmod.com/t/change-event-instance-parameter-from-another-script/23151/3 "2025-07-14T20:43:26Z")

</div>

> [@Connor\_FMOD](#):
>
> ```auto
> foreach (FMOD.Studio.EventInstance currEvent in instances)
> {
> result = currEvent.setParameterByName(ParameterName, ParameterValue);
> }
> 
> ```

Wow thank you so much, that was exactly it!

I have another question though, since this loops through all of the events created with this path, I’m guessing this script would change the parameter on 2 events triggered by different objects?  
In a co-op game, person A creates and plays the event and person B does so too, if I activate this script on person A it would change the parameter for both of them since it loops through all the created events right?

---

<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:** [July 17, 2025, 1:51am UTC](https://qa.fmod.com/t/change-event-instance-parameter-from-another-script/23151/4 "2025-07-17T01:51:07Z")

</div>

Correct, however we have solution for that too!

We can pass information to our instances with [FMOD Engine | Studio Api Eventinstance - Studio::Eventinstance::Setuserdata](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_setuserdata), for example whether the instance is for player 1 or 2. The simplest way is to pass the player `int` directly to the instance (if using a emitter, it can be retrieved with: [Unity Integration | Studioeventemitter::Eventinstance](https://fmod.com/docs/2.02/unity/api-studioeventemitter.html#studioeventemitter_eventinstance))

```auto
GCHandle playerHandle;
private int player = 1;

void Start()
{
    playerHandle = GCHandle.Alloc(player);

    instEvent = FMODUnity.RuntimeManager.CreateInstance(refEvent);

    FMOD.RESULT result = instEvent.setUserData(GCHandle.ToIntPtr(playerHandle));

    instEvent.start();
    instEvent.release();
}

private void OnDestroy()
{
    if (playerHandle.IsAllocated)
    {
        // Please make sure to free the handle or this will cause a memory leak! 
        playerHandle.Free();
    }
}

```

Then to check the player int is simple in our existing function!

```auto
foreach (FMOD.Studio.EventInstance currEvent in instances)
{
    IntPtr playerPtr;
    result = currEvent.getUserData(out playerPtr);

    GCHandle playerHandle = GCHandle.FromIntPtr(playerPtr);
    int player = (int)playerHandle.Target;
    if (player == 1)
    {
        result = currEvent.setParameterByName(ParameterName, ParameterValue);
    }
}

```

For another example of using `setUserData` have a look at our [Unity Integration | Examples Programmer Sounds](https://fmod.com/docs/2.02/unity/examples-programmer-sounds.html).

Hope this helps!

---

<div class="post-metadata">

**Author:** ![EpicMcDude](https://avatars.discourse-cdn.com/v4/letter/e/d6d6ee/32.png) [@EpicMcDude](https://qa.fmod.com/u/EpicMcDude)\
**Post date:** [July 18, 2025, 7:25pm UTC](https://qa.fmod.com/t/change-event-instance-parameter-from-another-script/23151/5 "2025-07-18T19:25:38Z")

</div>

Wow don’t think I’d had found this in the manual, I think this is exactly what I needed. Very much appreciated Connor, many thanks!

---

<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:** [July 20, 2025, 11:01pm UTC](https://qa.fmod.com/t/change-event-instance-parameter-from-another-script/23151/6 "2025-07-20T23:01:34Z")

</div>

No worries, if you have any more questions please do not hesitate to ask!
