EasyRhythm for FMOD - Open-Source Unity package!

For anyone getting started with FMOD & Unity, I’ve just put together a Unity package to help you with FMOD callbacks - particularly useful for rhythm games/mechanics or games that have behaviour tied to music and sound effects.

Free to download and use, you just have to add the FMOD package (from the asset store) to the project. Currently working with Unity 2019!

https://github.com/jleaney/EasyRhythm-for-FMOD

I hope to keep working on this and create something really solid that makes integrating with Unity and FMOD much simpler than it currently is, especially for solo/indie devs, or those without strong programming backgrounds.

1 Like

Have you found a way to get the next marker before it occurs? I can get the marker once it’s crossed through the FMOD callbacks, but I need to know when a marker is going to occur in the future.

I haven’t looked into it deeply, but I remember it being not something easily did - currently the simplest way to do it is to manually add your markers into the User Property field in FMOD, then get that data at runtime. You can use a Sorted List to figure out what the next marker will be, even if the song isn’t playing in a linear way (obviously won’t work in some situations though!). Here’s an example of what could work (inspired from this post: https://qa.fmod.com/t/can-you-access-a-list-of-markers-at-runtime/11819/4) -

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

public class GetMarkers : MonoBehaviour
{
    string nextMarker;

    [EventRef]
    public string myEventPath;
    public EventInstance myEventInstance;
    SortedList<string, string> myMarkerList;

    private void Start()
    {
        // Create the instance
        myEventInstance = RuntimeManager.CreateInstance(myEventPath);

        // Get a list of markers in your instance
        myMarkerList = GetMarkerList(myEventInstance);
    }

    private SortedList<string, string> GetMarkerList(EventInstance instance)
    {
        // Get the instance description
        EventDescription description;
        instance.getDescription(out description);

        // Get the length of user properties in the event (your manual list of markers)
        int userPropertyCount;
        description.getUserPropertyCount(out userPropertyCount);

        SortedList<string, string> markers = new SortedList<string, string>();

        // Add each property to our list of markers, using itself as the key
        for (int i = 0; i < userPropertyCount; i++)
        {
            USER_PROPERTY userProperty;
            description.getUserPropertyByIndex(i, out userProperty);

            markers.Add(userProperty.stringValue(), userProperty.stringValue());
            print("Added " + userProperty.stringValue() + " to the list.");
        }

        // Return the list of markers
        return markers;
    }

    // Get the index of the current marker the use it to determine what the next marker will be
    // Call this from whatever script is being called by the current marker
    public void UpdateNextMarker(SortedList<string, string> markers, string currentMarker)
    {
        int index = markers.IndexOfKey(currentMarker);
        nextMarker = markers.Values[index + 1];
    }

Not a proper implementation but shows how you can get the list of markers, up to you how to want to use that info…


This is where to input your marker data - for some reason the getUserProperty function returns the second item in the User Properties field, so I simply put a number in the first box to help keep track. Remember to keep the data here the exact same name as your actual markers.

6451971--722706--upload_2020-10-24_21-42-22.png

1 Like

I really wanna use this! but I keep running into an error when I import:


I at first assumed it was the version but I’ve tried it even in the version you list this works with. I’m unsure what’s causing this error…

Hmm, do you mean you’ve tried different unity versions, or different versions of the FMOD package? I’m pretty sure the latest FMOD package has some changes to the scripting side that might affect this!

Unity version… I hadn’t considered fmod versions… which version does this work with usually?

So sorry for the delayed reply, I’ve been away camping!! If you haven’t already got it working, the FMOD integration version I used to create this was 2.00.09, which I believe is only available via direct download as a package from the FMOD website (rather than via the Unity Asset Store).

Let me know if this resolves it or not!

  • Jake

I know it’s been a while since this thread has been active, but will there be future updates to this library? I wanted to see if I could make a rhythm game using it, and wanted to know how to allow the player to input slightly before or after the beat (timing window). Thanks!

EDIT: here is a concept I came up with, please let me know if there is a better way of doing this!

- the timer starts on one beat and has a duration in beats.
- while the timer is counting down, it keeps track of milliseconds elapsed
- it knows how many milliseconds should have passed by to get "perfect"
- difference between the time it is now and the time to get perfect : if it is negative or timer runs out you failed

Hello and thanks for your interest in this package! At this point it’s unlikely I’ll update it anytime soon, but maybe one day… :slight_smile:

This concept sounds pretty solid, but possibly a more accurate way you could approach it is by getting the timeline position directly from FMOD (EasyEvent.TimelineInfoInstance.currentTimelinePosition), rather than relying on Unity to count the milliseconds. If you get the timestamp (EasyEvent.TimelineInfoInstance.currentTimelinePosition) every time OnBeat() is called, then you could find the difference between the elapsed time since the beat was called, and the timestamp when the beat is called, based on FMOD’s calculations. You would also have to get the currentTimelinePosition every frame though to know the total time elapsed in ms, which be additional functionality you would need to add into the EasyEvent script’s update function. It wouldn’t be too hard, you’d just have to create a new function in IEasyListener called ‘OnTick(EasyEvent easyEvent)’ and then called that on all listeners from the EasyEvent script’s update function.

Maybe simpler to do your version, unless you’re confident with adding something like that! Sorry I don’t have the time to write something out for you, good luck :slight_smile: