# Repeat play the last music

**URL:** <https://qa.fmod.com/t/repeat-play-the-last-music/18124>\
**Category:** Unity\
**Tags:** unity\
**Created:** [December 21, 2021, 9:31am UTC](https://qa.fmod.com/t/repeat-play-the-last-music/18124 "2021-12-21T09:31:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tzqinglang](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@Tzqinglang](https://qa.fmod.com/u/Tzqinglang)\
**Post date:** [December 21, 2021, 9:31am UTC](https://qa.fmod.com/t/repeat-play-the-last-music/18124/1 "2021-12-21T09:31:59Z")

</div>

When I dynamically replace the events in sudioeventemitter, the previous music will be played agpublic

class test : MonoBehaviour  
{  
public Button a;  
public Button b;  
public StudioEventEmitter s;  
public void Start()  
{  
a.onClick.AddListener(()=\>{  
Play();  
});

```
    b.onClick.AddListener(()=>{
        Stop();
    });
}
public void Play()
{
    s.EventReference.Path = "event:/BGM/system/yongyan_theme";
    s.EventReference.Guid = RuntimeManager.PathToGUID("event:/BGM/system/yongyan_theme");
    s.Play();
}

public void Stop()
{
    s.Stop();
    s.EventReference.Path = "event:/BGM/system/lobby";
    s.EventReference.Guid = RuntimeManager.PathToGUID("event:/BGM/system/lobby");
    s.Play();
}

```

}ain

---

<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:** [December 23, 2021, 3:10am UTC](https://qa.fmod.com/t/repeat-play-the-last-music/18124/2 "2021-12-23T03:10:40Z")

</div>

There is currently no way to set the event on a Studio Event Emitter using script, there is some discussion on it [here](https://qa.fmod.com/t/how-do-i-change-the-event-in-fmod-studio-event-emitter-through-c-it-keeps-playing-the-same-previous-event/13928/6).  
You can try adding a method to the FMOD Studio Event Emitter that sets a new event:

```auto
// Assets/Plugins/FMOD/src/StudioEventEmitter.cs
public void ChangeEvent(string newEvent)
{
    EventReference = EventReference.Find(newEvent);
    EventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
    Lookup();
}

```

```auto
// test.cs
public void Play()
{
    s.ChangeEvent("event:/Music/Level 01");
    s.Play();
}

public void Stop()
{
    s.ChangeEvent("event:/Music/Level 02");
    s.Play();
}

```

The recommended approach is to create your own script. You can can take a look at how to call the FMOD Studio API yourself in the [Unity Basic Scripting Example](https://fmod.com/resources/documentation-unity?version=2.02&page=examples-basic.html).
