# Losing reference of EventInstance

**URL:** <https://qa.fmod.com/t/losing-reference-of-eventinstance/19648>\
**Category:** Unity\
**Tags:** unity, csharp\
**Created:** [December 16, 2022, 4:05pm UTC](https://qa.fmod.com/t/losing-reference-of-eventinstance/19648 "2022-12-16T16:05:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lookscozylabs](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/lookscozylabs/32/4386_2.png) [@lookscozylabs](https://qa.fmod.com/u/lookscozylabs)\
**Post date:** [December 16, 2022, 4:05pm UTC](https://qa.fmod.com/t/losing-reference-of-eventinstance/19648/1 "2022-12-16T16:05:26Z")

</div>

I have a grenade that needs a hissing sound effect and I’m using an EventInstance to hold it. I create and start the instance when I start aiming. When I go from aiming to throwing the grenade, I need to pass reference to the EventInstance to a new Grenade instance using the old Grenade instance.

```auto
public class Grenade : MonoBehaviour
{
    public EventInstance TimerSoundInstance;

    public void Init(GrenadeData data, float timeLeft, Grenade grenade)
    {
        if (grenade)
        {
            TimerSoundInstance = grenade.TimerSoundInstance;
        }
        else
        {
            TimerSoundInstance = AudioManager.Instance.CreateEventInstance(Data.TimerSound);
            TimerSoundInstance.start();
        }
    }
}

```

I’m storing the references in an AudioManager. When I go to remove the EventInstance from the list, stop it, and release it I see that it’s not in the list and stopping/releasing doesn’t stop the sound. If I debug, I can see that the original Grenade’s EventInstance handle is 2xxxxxx while after I pass it to the new grenade its 0. The EventInstance in the list has the 2xxxxxx handle and the EventInstance passed to StopEventInstance has a handle of 0.

```auto
public class AudioManager : SingletonManager<AudioManager>
{
    public List<EventInstance> ActiveEventInstances = new List<EventInstance>();

    public EventInstance CreateEventInstance(EventReference eventReference)
    {
        EventInstance eventInstance = RuntimeManager.CreateInstance(eventReference);
        ActiveEventInstances.Add(eventInstance);
        return eventInstance;
    }

    public void StopEventInstance(EventInstance eventInstance)
    {
        Debug.Log(ActiveEventInstances.Contains(eventInstance)); // returns false
        ActiveEventInstances.Remove(eventInstance);
        eventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
        eventInstance.release();
    }
}

```

Is this a bug or am I handling the EventInstance reference incorrectly? 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:** [December 19, 2022, 12:04am UTC](https://qa.fmod.com/t/losing-reference-of-eventinstance/19648/2 "2022-12-19T00:04:36Z")

</div>

Hi,

I was not able to recreate the issue with my own code. Would it be possible to have the full code or the project uploaded to your profile to test on my end?

---

<div class="post-metadata">

**Author:** ![lookscozylabs](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/lookscozylabs/32/4386_2.png) [@lookscozylabs](https://qa.fmod.com/u/lookscozylabs)\
**Post date:** [December 19, 2022, 1:00am UTC](https://qa.fmod.com/t/losing-reference-of-eventinstance/19648/3 "2022-12-19T01:00:24Z")

</div>

Turns out it was unrelated to FMOD. I wasn’t passing something I should’ve when I thought I was. You can mark as resolved/false alarm. Thanks!
