How can I go about syncing game events to beats in a song?
Ideally I could set a marker in FMOD at every beat I want something to happen (Say color on a unity object shifts from black to white on every other beat). Then create a script in Unity that listens for the marker?
Maybe this could also be done with automating a parameter? Could you could read what the parameter is set at for each frame?
I’d like to easily tailor where these shifts happen within FMOD.
If this isn’t possible, what’s a sound way to go about syncing game events to a beat?
Any help would be appreciated. Thanks!
Thanks for sharing this snippet, it helped me understand how to implement some beat-driven features in my own Unity project.
If I may ask a follow-up question, what kind of latency should we expect when receiving these callbacks, particularly the TIMELINE_BEAT callbacks? When using MonoBehaviour.Update to call FMOD.Studio.System.Update, I measure TIMELINE_BEAT callbacks occurring up to ±0.02s sooner/later than expected, and ±0.01s on average. When using MonoBehaviour.FixedUpdate instead, I still measure callbacks occurring up to ±0.02s sooner/later than expected, but ±0.00s on average. I am using UnityEngine.Time.realtimeSinceStartup to record timestamps.
These slight variations in period between callbacks are generally negligible for non-gameplay-critical features like beat-driven effects, but seem to be significant enough to cause trouble when trying to implement beat-driven input–sometimes input will be rejected because a callback occurred a little sooner or a little later than usual, for example.
The timeline processing occurs on the Studio thread once per Studio update (every 20ms). The beat callback is deferred for the main Unity update which will add some floating delay which is probably what you have seen.
It would be a nice feature for the callback structure to include some timing information that includes that delay, which would allow very accurate timing, but we don’t have any plans to implement that feature right now.
Hi, i’m rather new to unity and fmod integration, me being lazy was hoping nicholas wilcox’s snippet of code would build , however i am having a few problems setting up the code, initally i changed the line FMOD_StudioSystem.instance.GetEvent/ to FMODUnity.RuntimeManager.CreateInstance("event—
which solved an error, however IntPtr namePtr = marker.name; is throwing up an error, "cannot implicitly convert type FMOD.StringWrapper to system.IntPtr. I’m unsure as to the issue and how it could be resolved? any advice would be greatly appreciated