I need a way to run code much more frequently than update. Ideally, every 3 milliseconds

I’m working on an interactive music tool. The ear is much more sensitive to timing issues than the eye, and while Update’s frequency of 16 milliseconds is good enough for the eye, it’s far too slow for music.

Things sound “in sync” if they are within a tolerance of 5 milliseconds, water tight if they’re at 3.

So far, coroutines are too expensive to reach this speed, and changing the timestep isn’t an option, as it would interfere with the rest of the game. Even OnAudioFilterRead is only about 20 ms.

Is there a way to have code called at a frequency of less than 5 milliseconds?

You could try just using a C#/Mono thread… However, it seems like a bad idea to assume that you’ll be able to get ~333 calculations per second. On slower hardware especially…

You’ll probably also have to use busy-waiting because sleeping a thread tends to be hit and miss if you want exact timings.

My question is why dont you calculate what you need ahead of time? If you’re reacting to the music (rather than generating it) you have all the data you need before-hand. If you ARE generating the music on the fly, then would it be bad to have it be smooth but lagging behind by about 30ms?

If your tool doesn’t use the physics engine for anything, you could use FixedUpdate. It has a more consistent timing, and you can change the rate by going to Edit->Project Settings->Time and changing the Fixed Timestep.