# Best way to pause/unpause while keeping sync

**URL:** <https://qa.fmod.com/t/best-way-to-pause-unpause-while-keeping-sync/22354>\
**Category:** Unity\
**Created:** [November 28, 2024, 5:10pm UTC](https://qa.fmod.com/t/best-way-to-pause-unpause-while-keeping-sync/22354 "2024-11-28T17:10:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brettridel](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@brettridel](https://qa.fmod.com/u/brettridel)\
**Post date:** [November 28, 2024, 5:10pm UTC](https://qa.fmod.com/t/best-way-to-pause-unpause-while-keeping-sync/22354/1 "2024-11-28T17:10:12Z")

</div>

Hello

I’m developing a rhythm game. As others, I would like to keep the sync between music and game as close as possible.

Up to now, I always succeed to do that using EVENT\_CALLBACK, by synchronising the game on the first TIMELINE\_BEAT

However, I would like to pause/unpause, and sync the game when unpause is done.

I’m a little bit confused about the way it works.  
Here is one of my reference topic : [Some delay occurs when pause the music on Android](https://qa.fmod.com/t/some-delay-occurs-when-pause-the-music-on-android/19247)

First, to pause/unpause, we can call myChannel.setPause but also myEventInstance.setPause  
Is there a difference between the two ?

Second, if I apply the proposed method referenced in the above post (retrive channel, get dsp clock, set position), does the method setPause is synchronise, or is there an unknown delay between my call and the effective play ?  
If there is a delay, how may I know exactly when the music starts again and to know at which position (in ms) it unpause ? I’m asking, because there is absolutly no EVENT\_CALLBACK triggered after the unpause.

Thank you

---

<div class="post-metadata">

**Author:** ![brettridel](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@brettridel](https://qa.fmod.com/u/brettridel)\
**Post date:** [December 3, 2024, 3:27pm UTC](https://qa.fmod.com/t/best-way-to-pause-unpause-while-keeping-sync/22354/2 "2024-12-03T15:27:31Z")

</div>

In other words and in a more general question, is there a way to know the exact cursor position, accurate both in its position and in the delay to get the answer ?

---

<div class="post-metadata">

**Author:** ![benhoughton](https://avatars.discourse-cdn.com/v4/letter/b/8c91f0/32.png) [@benhoughton](https://qa.fmod.com/u/benhoughton)\
**Post date:** [December 4, 2024, 6:14am UTC](https://qa.fmod.com/t/best-way-to-pause-unpause-while-keeping-sync/22354/3 "2024-12-04T06:14:43Z")

</div>

rather than pause/unpause you could try instance.getTimelinePosition();  
stop the event  
then when you need it settimelineposition and start again.  
Unsure on the delay aspect

---

<div class="post-metadata">

**Author:** ![brettridel](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@brettridel](https://qa.fmod.com/u/brettridel)\
**Post date:** [December 9, 2024, 11:52pm UTC](https://qa.fmod.com/t/best-way-to-pause-unpause-while-keeping-sync/22354/4 "2024-12-09T23:52:02Z")

</div>

Thanks @benhoughton for the suggestion. It works, but I do not really understand why. Here is my new code

```auto
int pauseLastPos = 0;
public void PauseMusic(bool paused)
{
    if (paused)
    {
        musicInstance.getTimelinePosition(out pauseLastPos);
        musicInstance.setPaused(true);
    }
    else
    {
        musicInstance.getTimelinePosition(out int pauseLastPos2);
        musicInstance.setTimelinePosition(pauseLastPos);
        musicInstance.setPaused(false);
    }
}

```

What is strange is that if I comment the setTimelinePosition line, timeline starts to be out of sync after some pause/unpause, but uncomment this line allows to keep timeline sync (when I say timeline, I mean  
BeatEventCallback and EVENT\_CALLBACK\_TYPE).

Here is the strange point: in both situations (while calling or not setTimelinePosition), pauseLastPos and pauseLastPos2 have the same values, meaning I’m passing the same value in setTimelinePosition that I retrieve from getTimelinePosition.

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [December 19, 2024, 5:15am UTC](https://qa.fmod.com/t/best-way-to-pause-unpause-while-keeping-sync/22354/5 "2024-12-19T05:15:15Z")

</div>

Sorry for the delayed response!

What you’re likely running into is the [asynchronous nature of how the FMOD Studio system operates](https://www.fmod.com/docs/2.02/api/studio-guide.html#studio-system-processing). When called, almost all API commands, including `EventInstance.setPaused()`, are enqueued in a buffer that is submitted to the Studio system to execute asynchronously when [Studio.System.update()](https://www.fmod.com/docs/2.02/api/studio-api-system.html#studio_system_update) is called. The default update period is 20ms, meaning that would explain the drift you’re running into.

However, by accessing an EventInstance’s underlying ChannelGroup as detailed in the thread you linked, you can make these calls synchronously - notably [getting the DSP clock](https://www.fmod.com/docs/2.02/api/core-api-channelcontrol.html#channelcontrol_getdspclock) for sample accurate timing info, and calling [ChannelControl.setPaused()](https://www.fmod.com/docs/2.02/api/core-api-channelcontrol.html#channelcontrol_setpaused). I’d recommend trying this method of pausing out and seeing whether it resolves your issue. It’s worth noting however that due to the way the Studio and Core API interact, you’ll likely also need to call `EventInstance.setPaused()` on the event instance at the same time as calling `ChannelControl.setPaused()` to ensure that the pause states remain in sync.
