# Cant store EventInstances in the list

**URL:** https://qa.fmod.com/t/cant-store-eventinstances-in-the-list/21393
**Category:** Unity
**Tags:** csharp, unity
**Created:** [March 21, 2024, 4:04pm UTC](https://qa.fmod.com/t/cant-store-eventinstances-in-the-list/21393 "2024-03-21T16:04:07Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Bladd](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@Bladd](https://qa.fmod.com/u/Bladd)
#### Post date: [March 21, 2024, 4:04pm UTC](https://qa.fmod.com/t/cant-store-eventinstances-in-the-list/21393/1 "2024-03-21T16:04:07Z")

</div>

Hi.  
Im trying to store the EventInstance in the list after creation of the event , but error pops out NullReferenceException . I can start the event and it starts playing , but after i cant add it to the list.

Here is example of code:

```auto
            EventInstance audioEvent = CreateInstance(FMOD_Events.GetEventReference(audioName, FMOD_Events.Music));

            PlayLoop(audioEvent);

            eventInstances.Add(audioEvent);

```

---

<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: [March 22, 2024, 12:34am UTC](https://qa.fmod.com/t/cant-store-eventinstances-in-the-list/21393/2 "2024-03-22T00:34:49Z")

</div>

Hi,

What version of the FMOD Unity integration are you using?

Could I get the full script to test on my end?

I was able to add events to a list using the following code:

```auto
private List<FMOD.Studio.EventInstance> eventList = new List<FMOD.Studio.EventInstance> ();
// Start is called before the first frame update
void Start()
{
    eventList.Add(FMODUnity.RuntimeManager.CreateInstance($"event:/Music/Level 01"));
    eventList.Add(FMODUnity.RuntimeManager.CreateInstance($"event:/Music/Level 02"));

    for (int i = 0; i < eventList.Count; i++)
    {
        eventList[i].start();
        eventList[i].release();
    }
}

// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown(KeyCode.Escape))
    {
        for (int i = 0;i < eventList.Count;i++)
        {
            eventList[i].stop(STOP_MODE.IMMEDIATE);
        }
    }
}

```

Hope this helps.

---

<div class="post-metadata">

### Author: ![miikakan](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@miikakan](https://qa.fmod.com/u/miikakan)
#### Post date: [March 22, 2024, 9:51am UTC](https://qa.fmod.com/t/cant-store-eventinstances-in-the-list/21393/3 "2024-03-22T09:51:40Z")

</div>

Wherever you have declared the list, make sure it is not null.

As Connor’s code has:  
`private List<FMOD.Studio.EventInstance> eventList = new List<FMOD.Studio.EventInstance> ();`

So the `... = new List<...>();` is the important part here, and not having it is probably causing the NullReferenceException.
