# Syncing scripts to beats/start of measures?

**URL:** https://qa.fmod.com/t/syncing-scripts-to-beats-start-of-measures/15305
**Category:** Unity
**Created:** [December 10, 2019, 9:02pm UTC](https://qa.fmod.com/t/syncing-scripts-to-beats-start-of-measures/15305 "2019-12-10T21:02:13Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![pytty](https://avatars.discourse-cdn.com/v4/letter/p/c6cbf5/32.png) [@pytty](https://qa.fmod.com/u/pytty)
#### Post date: [December 10, 2019, 9:02pm UTC](https://qa.fmod.com/t/syncing-scripts-to-beats-start-of-measures/15305/1 "2019-12-10T21:02:13Z")

</div>

**I’m making a rhythm game, where the user has to press buttons in sync with symbols moving on a track (think Guitar Hero or Dance Revolution)**. I’ve got the track, the button patterns and everything working by a script called Rhythm.cs, but I still need to **sync the rhythm patterns to the music played by FMOD**. I’ve searched everywhere about beat syncing in FMOD, and all lead to this tutorial: [https://www.fmod.com/resources/documentation-unity?version=2.0&page=examples-timeline-callbacks.html](https://www.fmod.com/resources/documentation-unity?version=2.0&page=examples-timeline-callbacks.html)

But to me that just looks like a blob of code without any instructions how to use it, or how to do different things. Could anyone please help me understand and use it?

**What I need is:**  
**1. Fetch tempo** of the music from FMOD to Rhythm.cs. Maybe also time signature, but everything is 4/4 by default.  
**2.** I need to **wait to the start of a measure** to start the rhythm game in Rhythm.cs, so that the button pattern will align to the beats. So I need FMOD to tell me when the next measure starts. I don’t know if it’s necessary, but I’ve added markers in FMOD Studio into start of every measure, just in case.  
3. I probably need to check the **start of the measures periodically** , so the patterns stay in sync.  
4. Alternatively it would be good to get info of every beat, but start of the measures will be fine for now.  
5. Also, the music is going to loop obviously, so it has to work with that.

Can anyone please help me to get started?

---

<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: [December 16, 2019, 11:15pm UTC](https://qa.fmod.com/t/syncing-scripts-to-beats-start-of-measures/15305/2 "2019-12-16T23:15:09Z")

</div>

The [`FMOD_STUDIO_TIMELINE_BEAT_PROPERTIES`](https://www.fmod.com/resources/documentation-api?version=2.0&page=studio-api-eventinstance.html#fmod_studio_timeline_beat_properties) used in the callback contains information like tempo, time signature, bar, beat and timeline position.

There are a number of other callbacks you can register for as well, [`FMOD_STUDIO_EVENT_CALLBACK_TYPE`](https://www.fmod.com/resources/documentation-api?version=2.0&page=studio-api-eventinstance.html#fmod_studio_event_callback_type).

---

<div class="post-metadata">

### Author: ![jacobleaney](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jacobleaney](https://qa.fmod.com/u/jacobleaney)
#### Post date: [July 25, 2020, 9:50am UTC](https://qa.fmod.com/t/syncing-scripts-to-beats-start-of-measures/15305/3 "2020-07-25T09:50:19Z")

</div>

Did you ended up working this out?

I’m working on a little package with two features that make rhythm games really simple:

- Any method can be called on the beat (or on any specific beat/bar, every second beat etc.)
- Any method can be called based on an FMOD marker (eg. create a destination marker in FMOD and a method of the same name will be called on any object (MonoBehaviour) in Unity.

The package is still rough around the edges but I could share it with you privately for now if you just want something to get you started!

Jake

---

<div class="post-metadata">

### Author: ![pullaposki](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/pullaposki/32/1761_2.png) [@pullaposki](https://qa.fmod.com/u/pullaposki)
#### Post date: [December 8, 2020, 9:09am UTC](https://qa.fmod.com/t/syncing-scripts-to-beats-start-of-measures/15305/4 "2020-12-08T09:09:43Z")

</div>

Hello.

I would be very interested in this package if you would be willing to share it.

Thanks in advance!

-Janne

---

<div class="post-metadata">

### Author: ![jacobleaney](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jacobleaney](https://qa.fmod.com/u/jacobleaney)
#### Post date: [October 5, 2021, 1:52am UTC](https://qa.fmod.com/t/syncing-scripts-to-beats-start-of-measures/15305/5 "2021-10-05T01:52:48Z")

</div>

WAY late to this, but just in case anyone else is interested -

> **[GitHub - jleaney/EasyRhythm-for-FMOD](https://github.com/jleaney/EasyRhythm-for-FMOD)**
>
> Contribute to jleaney/EasyRhythm-for-FMOD development by creating an account on GitHub.

Haven’t touched this for a while but I think it mostly works alright!
