I’m a hardware audio design engineer who designs PCM bus and audio serial interfaces for a living. I was scoffing at this at the beginning, but ended up stealing all the code
@@b3agzIt's been 4 years since your videos first got me into really programming my own projects (my boxes engine) and I'm once again led back to you lmao
I know 99% of people who see this can easily figure it out, but by adding a Slider control to the BeatController script, you can control this in game by setting the pitch of the audio source to the value of the Slider. Great tutorial!!!
I was trying to accomplish the same effect with Coroutines and WaitForSeconds(), but that wasn't perfect (it desynced every now and then). Your solution is much more elegant and useful! Thanks for the tips!!! PS: The steps thing is called note length. *2 would be a half note (2 notes per beat), *4 - a quarter note etc. And I guess 0.5 would be "half-time". (I'm not a very good musician, though. So take it with a grain of salt)
Thank you so much for this video! Trying to get audio to sink to a beat has been the bane of my existence across so many engines, and yet this works well and was surprisingly simple to follow!
This is genuinely brilliant. I've been working on my university project for some time and was getting frustrated with the game being out of sync with my music, especially given the song is fast paved so it's very obvious very quick. This couldn't have been shown to me at a better time!
For as long as I can remember I've been curious about how I could synchronize enemy attacks with the music, and this is the most complete I've seen. Thank you very much :)
I'm just starting my internship and I'm very new at Unity but I was told to learn it and research on topics I'd like to know. I'd like to work with music and audio, I do some music myself as well, so this was a good start. I did some changes, like setting an offset to the beats so they would align to the down beat for example, added a start delay for songs that are not made to loop. This was a very good starting point for someone that knows some programming and knows a little bit abut music.
@@saing_rbn5368 Well, tbh the solution is not very elegant because it's proportionally inverse to how we understand beats, but I'll try to explain: what we want to modify is when the rhythm trigger/interval happens right? So in that class declare a float, I called mine " private float _phaseOffset = 0f;", you can add the [serializefield] to tweak it in the menus. Then since it's a fixed value, it will move the beat at a fixed rate when it's checked by doing "int currentPulse = Mathf.FloorToInt(pulse + _phaseOffset);" after that you do the check "if (currentPulse != _lastPulse) " and the operation to update the pulse and trigger it in the method "checkforNewInterval". The values of the offset have to be set between 0~1, more will just cycle over.
Great video! I made a small rhythm game for a game jam where you have to interact on the beat, but it wasn't synced properly. This tutorial helped me get it working better.
i was so stuck using fixedUpdate, altering timesteps, time.time multiplied by blah blah, using different ways but the game kept getting out of sync after a few minutes. thank you so much
I don't know if anyone mentioned it but a good name for the _steps variable would be _subdivisions I think. As musicians, we subdivide a beat in our head to help us visualize rhythms which is essentially what you're doing with transforming something like a whole note into half notes, quarter notes, eighth notes, etc.
Mind sharing the code/script? I'm making a rhythm game myself and would really like something that can switch tempo on the fly without manually inserting it
I’m working on an all-around sound and music management system for Unity native audio, and was not sure how to accurately track beats to assist with more precise music transitions. I think this is a great way to get me started. Thanks!
Fantastic tutorial. Glad I decided to consult RU-vid. It was a little hard to follow at the pace of the video but after going back and forth a few times I got it. Thanks so much!
The music used in the video is piece by Johnnie Holiday kindly released as a CC0 track ( freesound.org/people/Johnnie_Holiday/sounds/563651/ ) and the asset pack used is Unity's own free 3D Game Kit ( assetstore.unity.com/packages/templates/tutorials/3d-game-kit-115747?aid=1101l9Tam& )
Thats so great. What a cool idea to write a script for that issue to figure out how to do things on beats. :) pls more of that kind of small helpful scripts that solving one issue.
Thanks! If you have things you'd like me to tackle let me know. Can't promise I'm smart enough to solve it but I love trying to figure things like this out.
I saw this video some time ago that would actually fix some problem I had with my game. But unfortunatly I'm using FMOD and the game is porting to android. I tried a lot but honestly I think i'm going back to built in and using this I'm fed up with FMOD.
It should. As long as your BPM variable correct for track at any given moment, it will always be in sync with the music, even if the BPM changes. You just need to make sure your BPM variable is always right.
@@b3agz hmm, I see. I have an incremental game with a background beat that increases linearly from 80bpm to 160bpm in 92 seconds (numbers are not exact). I can't figure out a way to make it completely sync to the whole thing, since the gameplay itself consists of a ball going back and forth, at a certain speed that increases every x seconds. I kind of came back to hardcoding certain speeds, since I couldn't find a way to change the speed according to the increasing BPM down to floating point precision, but your tutorial was still really informative. the problem is that it cannot be synced at really fast speeds since it desyncs so easily and I can't find the exact 15+ decimal points number for acceleration to keep it consistent with the beat. thanks for the reply!
If I'm understanding you right, you should be able to use the UnityEvents system to trigger a "beat" and then just check if the beat is currently triggered.
FOR PEOPLE WHO PUT IN THIS CODE BEFORE REALISING IT'S FOR BEATS, NOT PRE RECORDED TRACKS First of all, you need ```using System.Linq;``` This might take a while, but you can add ```[SerializeField] private float[] _skips;``` to the start of Intervals and then do ```if(!(_skips.Contains(_lastInterval))) { // _trigger.invoke, etc}```. Then you can put every note to skip if there is no beat there.
I have a pre-made music with its beat being a core part. I now wanted to use it for a rhythm puzzle game. Can you explain this solution? Somehow my object is still out of sync with TestBeat() and the BPM variable doesn't seem to be affecting it for some reason. I'm still looking through it.