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
@b3agz9 ай бұрын
I'm pinning this 😂
@pureay27005 ай бұрын
@@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
@prispalos Жыл бұрын
This is **the definitive way** to handle beat matching in Unity. You can't even imagine how much you saved me with this video. Cheers!!
@b3agz Жыл бұрын
Glad it helped!
@labyrinthHealth4 ай бұрын
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!!!
@itmightbeMishu Жыл бұрын
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)
@trulyazul41625 ай бұрын
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!
@feli7487 Жыл бұрын
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 :)
@Joey-tb8fh Жыл бұрын
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!
@Vintagestep8 ай бұрын
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_rbn53682 ай бұрын
How did you manage the offset?
@Vintagestep2 ай бұрын
@@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.
@I-OGameDev5 ай бұрын
Bro explained the math so well I went straight in and built it first try
@seaweeddol81717 ай бұрын
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.
@b3agz7 ай бұрын
Awesome! Glad it helped.
@marionateixido17897 ай бұрын
Hi! can you share or explain how you coded the part of interacting on the beat? I'm trying to do the same for a game and I'm having some problems
@letenebrae3164 Жыл бұрын
Hifi-rush got me really curius on how music syncing works and this tutorial helped me a lot 😄
@CarlitoxBanana4 ай бұрын
Best video so far!!!
@dustydudle880 Жыл бұрын
Finally! An advertisement that's something I'm actually interested in, and it doesnt even ask me to go to a website for answers!
@kylopootis6489 Жыл бұрын
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
@b3agz Жыл бұрын
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& )
@overjuiced Жыл бұрын
Fantastic tutorial. Glad I decided to consult KZbin. 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!
@brockproosdy8066 Жыл бұрын
absolutely brilliant video, very underrated. Saved my ass more than once
@wolfeygamedev1688 Жыл бұрын
super cool! I added a scriptableobject that contains the audioclip and the BPM to be able to switch songs and have the BPM for it.
@leomassafm160 Жыл бұрын
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
@wolfeygamedev1688 Жыл бұрын
@@leomassafm160 well you still have to manually insert the bpm as a field of the SO
@leomassafm160 Жыл бұрын
@@wolfeygamedev1688 does the scriptableobject also take into account mid-song tempo changes? Rock songs have a lotta fluctuations in tempo...
@owencoopersfx Жыл бұрын
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!
@keviin08 ай бұрын
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.
@enchantgames_ Жыл бұрын
this was perfect! You are an angel!
@_NEWN_9 ай бұрын
Very helpful. Thank you bro!
@gabrielwhite9881 Жыл бұрын
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.
@b3agz Жыл бұрын
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.
@JohnnieHoliday Жыл бұрын
Nice! Thanks for support!
@b3agz Жыл бұрын
Thank you for making a great tune :D
@random32i8 Жыл бұрын
one thing i've found doesnt work with this well is having a song with a dynamic bpm because it makes the interval variable just randomly move around
@cimaaaaaaa2 ай бұрын
love it
@sneakysunset17654 ай бұрын
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.
@Kiru176 Жыл бұрын
For some reason I still have an issue with syncing. Also the bpm doesn't seem to do anything for some reason?
@candenizgumus5308 Жыл бұрын
art
@Demisemæn Жыл бұрын
bro, why you dont use the fft blackman harris formula from unity?
@nefelibata26311 ай бұрын
if my BPM increases linearly, will changing the corresponding BPM variable inside my game at the same time work with this code?
@b3agz11 ай бұрын
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.
@nefelibata26311 ай бұрын
@@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!
@_NEWN_9 ай бұрын
I had a question if you don't mind. How would I make it so that if you press a certain button on one of the beats per minute, something happens?
@b3agz9 ай бұрын
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.
@felixfontain6423 Жыл бұрын
When comes the Showreveal of Jam3
@b3agz Жыл бұрын
Should be up towards the end of this coming week.
@davidharmon7467 Жыл бұрын
Simples!
@AlexGeek2 ай бұрын
This reminds me of Pineapple on Pizza game.
@RazeGames654 Жыл бұрын
Can it be used in 2D objects??
@b3agz Жыл бұрын
Yes, you can use it with any game object. There's no fundamental difference between a 2d and a 3d object to unity.
@felixfontain6423 Жыл бұрын
First
@uuhhhhhhhhhhhhhhhhhhhhhhhhhh11 ай бұрын
Thank you, @b3agz! 🔊🔊🔊🔊🔊
@Sacroooooooooooooooooooooooooo Жыл бұрын
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.
@Kiru176 Жыл бұрын
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.