# Sync game events to music beats?

**URL:** <https://qa.fmod.com/t/sync-game-events-to-music-beats/12111>\
**Category:** Unity\
**Created:** [October 25, 2015, 4:32am UTC](https://qa.fmod.com/t/sync-game-events-to-music-beats/12111 "2015-10-25T04:32:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)\
**Post date:** [October 26, 2015, 12:28am UTC](https://qa.fmod.com/t/sync-game-events-to-music-beats/12111/2 "2015-10-26T00:28:12Z")

</div>

If you set a tempo marker on the timeline in Studio then markers are automatically quantized to the beat (hold ctrl to dragging a marker to disable quantization).

If you want to get every beat, simply use the beat callback.

```
public class MarkerDemo : MonoBehaviour 
{
    FMOD.Studio.EventInstance instance;
    FMOD.Studio.EVENT_CALLBACK cb;

    void Start()
    {
        instance = FMOD_StudioSystem.instance.GetEvent("event:/Music/Complex/Situation_Oriental");
    

        cb = new FMOD.Studio.EVENT_CALLBACK(StudioEventCallback);
        instance.setCallback(cb, FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER | FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT);
        instance.start();
    }

    public FMOD.RESULT StudioEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr eventInstance, IntPtr parameters)
    {
        if (type == FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER)
        {
            FMOD.Studio.TIMELINE_MARKER_PROPERTIES marker = (FMOD.Studio.TIMELINE_MARKER_PROPERTIES)Marshal.PtrToStructure(parameters, typeof(FMOD.Studio.TIMELINE_MARKER_PROPERTIES));
            IntPtr namePtr = marker.name;
            int nameLen = 0;
            while (Marshal.ReadByte(namePtr, nameLen) != 0) ++nameLen;
            byte[] buffer = new byte[nameLen];
            Marshal.Copy(namePtr, buffer, 0, buffer.Length);
            string name = Encoding.UTF8.GetString(buffer, 0, nameLen);
            if (name == "HIGH")
            {
                UnityEngine.Debug.Log("Reached high intensity marker");
            }
        }
        if (type == FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT)
        {
            FMOD.Studio.TIMELINE_BEAT_PROPERTIES beat = (FMOD.Studio.TIMELINE_BEAT_PROPERTIES)Marshal.PtrToStructure(parameters, typeof(FMOD.Studio.TIMELINE_BEAT_PROPERTIES));
        }
        return FMOD.RESULT.OK;
    }
}
```

---

_[View the full topic](https://qa.fmod.com/t/sync-game-events-to-music-beats/12111)._
