I'm trying to make an object's movement automatically sync to the music in Unity. I want a way to get the "key points" (when there is a loud beat) and make the object dash at those moments.

Basically, I just want the object to feel like it is synced with the music.

So how would I be able to get these points? A simple code or an explanation of a function I could use would be appreciated.

  • \$\begingroup\$ You may be interested in some of our past questions about performing beat detection and synchronizing gameplay to beats in Unity. This is unfortunately not a simple task. If you know the tracks in advance, you can manually annotate the time codes when something should happen. If you want to react to music supplied at runtime by the player, you have a much harder task, and you'll probably want to use proven middleware for it rather than reinvent the wheel yourself. \$\endgroup\$
    – DMGregory
    Nov 19, 2023 at 12:30
  • \$\begingroup\$ @DMGregory Thank you :) I was able to find a beat detection example and used it \$\endgroup\$
    – Howler
    Nov 22, 2023 at 12:52
  • \$\begingroup\$ Did you use an example from one of the existing Q&A threads here? If not, would you like to document the solution you used as a new Answer to help future searchers? \$\endgroup\$
    – DMGregory
    Nov 22, 2023 at 12:56
  • \$\begingroup\$ @DMGregory Okay sure! \$\endgroup\$
    – Howler
    Nov 22, 2023 at 13:06

1 Answer 1


I used an open source code to do this.

It's a Unity project by retrogeek46 and the link is: https://github.com/retrogeek46/Beat-Detection---Unity

In the project there is a script which detects a beat and changes the cube's color (in the Update()) when a beat occurs.

  • \$\begingroup\$ Please note that answers on Stack Exchange should answer the question directly, and not just link to another website that contains the answer. See also Are answers that just contain links elsewhere really "good answers"? on Meta-Stackexchange. To improve this answer, you could dive deeper into that git repository to find out how exactly it accomplishes beat detection and explain their approach in your answer. \$\endgroup\$
    – Philipp
    Nov 22, 2023 at 16:49
  • \$\begingroup\$ Showing code for how you used the API provided by this package to integrate it into your game would also be helpful to future readers, who can learn from your example. \$\endgroup\$
    – DMGregory
    Nov 22, 2023 at 17:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .