# Pausing Music and Resuming from Same Location?

**URL:** <https://qa.fmod.com/t/pausing-music-and-resuming-from-same-location/13635>\
**Category:** FMOD Studio\
**Created:** [January 11, 2018, 12:15am UTC](https://qa.fmod.com/t/pausing-music-and-resuming-from-same-location/13635 "2018-01-11T00:15:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kknupp](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/kknupp/32/59_2.png) [@kknupp](https://qa.fmod.com/u/kknupp)\
**Post date:** [January 11, 2018, 12:15am UTC](https://qa.fmod.com/t/pausing-music-and-resuming-from-same-location/13635/1 "2018-01-11T00:15:32Z")

</div>

Hi everyone!

I have a question regarding music integration. I’m hoping someone can help.

In this game I’m working on we have music that is triggered in the main level, but when a player enters a building that music stops until the player exits the building.

Upon exiting the building the music comes back on but always starts at the beginning of the piece.

Is it possible in F-MOD to set it up so that when exiting a building the music resumes from where it left off before the player entered the building?

Thanks,  
Kristi

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [January 11, 2018, 12:32am UTC](https://qa.fmod.com/t/pausing-music-and-resuming-from-same-location/13635/2 "2018-01-11T00:32:30Z")

</div>

It sounds like you might be calling Play on the sound to resume it after the pause.  
Calling play on an event will start it from the beginning, you need to use setPaused(false) to resume a paused event.

[https://fmod.com/resources/documentation-api?page=content/generated/FMOD\_Studio\_EventInstance\_SetPaused.html#/](https://fmod.com/resources/documentation-api?page=content/generated/FMOD_Studio_EventInstance_SetPaused.html#/)

---

<div class="post-metadata">

**Author:** ![kknupp](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/kknupp/32/59_2.png) [@kknupp](https://qa.fmod.com/u/kknupp)\
**Post date:** [January 11, 2018, 12:44am UTC](https://qa.fmod.com/t/pausing-music-and-resuming-from-same-location/13635/3 "2018-01-11T00:44:51Z")

</div>

> [@](#):
>
> It sounds like you might be calling Play on the sound to resume it after the pause.  
> Calling play on an event will start it from the beginning, you need to use setPaused(false) to resume a paused event.
> 
> [https://fmod.com/resources/documentation-api?page=content/generated/FMOD\_Studio\_EventInstance\_SetPaused.html#/](https://fmod.com/resources/documentation-api?page=content/generated/FMOD_Studio_EventInstance_SetPaused.html#/)

Thank you Cameron. Is this something on the code side? So I need to set my event up in F-Mod Studio any differently? I just have an event set to looping, nothing fancy.

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [January 11, 2018, 12:48am UTC](https://qa.fmod.com/t/pausing-music-and-resuming-from-same-location/13635/4 "2018-01-11T00:48:37Z")

</div>

Just the code, you don’t need to change the event at all.

Use EventInstance.setPaused(true) to pause.  
And EventInstance.setPaused(false) to resume.

---

<div class="post-metadata">

**Author:** ![kknupp](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/kknupp/32/59_2.png) [@kknupp](https://qa.fmod.com/u/kknupp)\
**Post date:** [January 11, 2018, 1:29am UTC](https://qa.fmod.com/t/pausing-music-and-resuming-from-same-location/13635/5 "2018-01-11T01:29:32Z")

</div>

Awesome thanks!

---

<div class="post-metadata">

**Author:** ![m\_daniel26](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@m\_daniel26](https://qa.fmod.com/u/m_daniel26)\
**Post date:** [August 26, 2023, 12:28am UTC](https://qa.fmod.com/t/pausing-music-and-resuming-from-same-location/13635/6 "2023-08-26T00:28:55Z")

</div>

> [@kknupp](#):
>
> a

I’m trying to do the same thing, and followed the suggestion laid out here, but I’m getting a console error:

‘EventInstance’ does not contain a definition for ‘EventInstance’ and no accessible extension method ‘EventInstance’ accepting a first argument of type ‘EventInstance’ could be found (are you missing a using directive or an assembly reference?

Here’s my script:

```auto
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FMOD.Studio;
using FMODUnity;

public class MusicManager : MonoBehaviour
{
    public FMOD.Studio.EventInstance levelMusic;
    public GameObject pauseMenuOB;
    private bool pauseMenuOn;

    void Awake()
    {
        PauseMenu pauseMenu = pauseMenuOB.GetComponent<PauseMenu>();
        pauseMenuOn = pauseMenu.pauseMenuOn;

        levelMusic = FMODUnity.RuntimeManager.CreateInstance("event:/Music/Chapter1/1_1_Lobby");
        levelMusic.start();
    }

    void Update()
    {
        PauseMenu pauseMenu = pauseMenuOB.GetComponent<PauseMenu>();
        pauseMenuOn = pauseMenu.pauseMenuOn;

        if (pauseMenuOn) levelMusic.EventInstance.setPaused(true);

        else if (!pauseMenuOn) levelMusic.EventInstance.setPaused(false);
    }
}

```

Not sure what I’m doing wrong here, any ideas?

---

<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:** [August 27, 2023, 11:05pm UTC](https://qa.fmod.com/t/pausing-music-and-resuming-from-same-location/13635/7 "2023-08-27T23:05:39Z")

</div>

Hi,

Your `levelMusic` is the [FMOD Engine | Studio API Reference - Event Instance](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html) created by [Unity Integration | Scripting API Reference - RuntimeManager::CreateInstance](https://fmod.com/docs/2.02/unity/api-runtimemanager.html#createinstance).

The solution should be removing the `EventInstance` from both the `setPaused()` function calls.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![m\_daniel26](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@m\_daniel26](https://qa.fmod.com/u/m_daniel26)\
**Post date:** [August 28, 2023, 6:41pm UTC](https://qa.fmod.com/t/pausing-music-and-resuming-from-same-location/13635/8 "2023-08-28T18:41:16Z")

</div>

Okay, so I modified the Update to this:

```auto
void Update()
    {
        PauseMenu pauseMenu = pauseMenuOB.GetComponent<PauseMenu>();
        pauseMenuOn = pauseMenu.pauseMenuOn;

        if (pauseMenuOn) EventInstance.setPaused(true);

        else if (!pauseMenuOn) EventInstance.setPaused(false);
    }

```

But now, I’m getting an Object Reference error: “An object reference is required for the non-static field, method, or property ‘EventInstance.setPaused(bool)’”

---

<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:** [August 28, 2023, 11:05pm UTC](https://qa.fmod.com/t/pausing-music-and-resuming-from-same-location/13635/9 "2023-08-28T23:05:11Z")

</div>

Hi,

Apologies, I wasn’t very clear. It would be like this:

```auto
void Update()
{
    PauseMenu pauseMenu = pauseMenuOB.GetComponent<PauseMenu>();
    pauseMenuOn = pauseMenu.pauseMenuOn;

    if (pauseMenuOn) levelMusic.setPaused(true);

    else if (!pauseMenuOn) levelMusic.setPaused(false);
}

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![m\_daniel26](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@m\_daniel26](https://qa.fmod.com/u/m_daniel26)\
**Post date:** [August 29, 2023, 9:53pm UTC](https://qa.fmod.com/t/pausing-music-and-resuming-from-same-location/13635/10 "2023-08-29T21:53:33Z")

</div>

Yep, that did the trick! Thank you!
