GetTimelinePosition accuracy for rhythm game

Kia ora,

I’m trying to make a rhythm game in Unity using FMOD and I’m having trouble getting accurate timeline position info. At the moment I just have a simple system where when the player clicks it will log how many milliseconds early or late you were from the beat.

The number I’m getting back with getTimelinePosition() seems to consistently be ~150ms higher than expected, which isn’t ideal. Is there anything I might be doing wrong or some way I can get more accurate timing information?

// In the music manager class
public int GetTimelinePosition()
    {
        musicInstance.getTimelinePosition(out int position);
        return position;
    }

// In the player class
private void FirePressed(InputAction.CallbackContext obj)
    {
        print(MusicManager.instance.GetTimelinePosition());
    }

Hi,

Due to the nature of the FMOD system, i.e. commands are queued up and executed asynchronously when the system is updated, and the fact that Studio updates (by default) every 20ms, there will likely always be a very slight difference between the expected and actual timeline position; however, this is normally extremely small, and nowhere near 150ms.

You may wish to try using ChannelControl::getDSPClock on an event’s underlying ChannelGroup to retrieve more accurate timing info. If the asset isn’t set to stream, and the difference from the DSP clock is similarly significant, could I get you to provide your Unity, FMOD Studio, and FMOD for Unity version numbers, and upload your FMOD Studio project to the uploads tab of your FMOD Profile so I can try to reproduce the issue?

On the topic of more accurate timing information, you may also wish to look into using timeline callbacks - they allow you to define code yourself that is called by the FMOD System upon reaching certain points in the event timeline, such as markers or beats, which is typically good for rhythm games. If that sounds like something that would be useful, our Unity docs have a basic timeline callbacks example script that I would recommend taking a look at.