Syncronise animation of instantiated objects

I’m making a 2D musical exploration game. There is a bit where there is a crowd of creatures moving in time with the music. I instantiate them randomly to create the crowd, but now their animations are all out of sync, since they are instantiated ad different times. How can I make sure the animations are all moving in sync? Thanks

Probably the easiest way is to start the animations over on every beat (or bar, or phrase, or whatever you’re syncing the animations to). Since you know when the music started and its beats-per-minute, you can calculate the number of the current beat by:

beat = audioSource.time / (bpm * 60)

Every time this goes up by a whole number, start the animations over. You could pass that as an event into MecAnim (or your animation code).

If you want to sync every 4 beats, just divide by 4.