# Change event in runtime

**URL:** <https://qa.fmod.com/t/change-event-in-runtime/18161>\
**Category:** Unity\
**Created:** [December 31, 2021, 5:59pm UTC](https://qa.fmod.com/t/change-event-in-runtime/18161 "2021-12-31T17:59:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![copertino1984](https://avatars.discourse-cdn.com/v4/letter/c/49beb7/32.png) [@copertino1984](https://qa.fmod.com/u/copertino1984)\
**Post date:** [December 31, 2021, 5:59pm UTC](https://qa.fmod.com/t/change-event-in-runtime/18161/1 "2021-12-31T17:59:48Z")

</div>

hi all, congratulations for fmod 💯, i am a beginner entering the world of fmod. I am programming a drum machine, I wanted to know how I can change event in runtime? I use version 2.02.05  
i tried to do

```auto
public class playb : MonoBehaviour
{ private FMOD.Studio.EventInstance instance;
      public string[] sample;
     int ind;

  void selectSAMPLE()
  {instance = FMODUnity.RuntimeManager.CreateInstance(sample[ind]);}

  void PLAY()
  {instance.start();
  instance.release();
  }
}

```

the goal is to change samples while it is in runtime …  
I created 1 event for each sample and I would like … is this correct?  
but I don’t know why the code doesn’t work 🤔

---

<div class="post-metadata">

**Author:** ![copertino1984](https://avatars.discourse-cdn.com/v4/letter/c/49beb7/32.png) [@copertino1984](https://qa.fmod.com/u/copertino1984)\
**Post date:** [January 1, 2022, 5:37pm UTC](https://qa.fmod.com/t/change-event-in-runtime/18161/2 "2022-01-01T17:37:36Z")

</div>

no response??

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [January 5, 2022, 12:55am UTC](https://qa.fmod.com/t/change-event-in-runtime/18161/3 "2022-01-05T00:55:46Z")

</div>

That should be enough to change the event at runtime, though I can see a couple of reasons why this script alone wouldn’t result in any audio playing back. To start with, are you calling these methods anywhere? For example, a fixed update loop that calls these functions would be a good start for a drum machine

```cs
int timeCounter = 0;
private void FixedUpdate() // Called 50 times per second
{
    if(timeCounter++ == 0)
    {
        selectSAMPLE();
        PLAY();
        ind = (ind + 1) % sample.Length;

    }
    timeCounter = timeCounter % 10;
}

```

Also, you will need to make sure that elements in your `sample` array are the correct string paths, for example “event:/Music/Kick”, “event:/Music/Snare” etc. You can get these by right clicking on the event in FMOD Studio and selecting “Copy Path”.  
If you haven’t already, I would recommend following with the [Unity Integration Tutorial](https://fmod.com/resources/documentation-unity?version=2.02&page=integration-tutorial.html) to get you started with Unity FMOD scripting if you are new to FMOD / Unity / Scripting in general.
