timed collision sounds lag out. Ideas why?

I’m working on a project with a high school student where he instantiates balls over cubes and on collision it the cube plays a note. The rhythm needs to constant and exact or your ear easily catches the delays in arpeggiation.

I’ve used fixedupdate in hopes to retain a steady beat. We’re using if (Time.time > NextFire) to limit the speed the balls come out.

The audio files are extremely short blips. We have no graphics.

We hear seemingly random ‘lags’. The only thing I can think that would be causing the problem is the the Firerate is set to 0.5f and the actual passes per second on the Update or FixedUpdate aren’t cleanly divisible by .5 and time.time making a small but noticeable delay.

Any suggestion how to make it stay on tempo and not lag out at all?

In Audio Manager, set DSPBuffer Size to Best Performance.

You can also play with the audio settings manually.

https://docs.unity3d.com/Documentation/ScriptReference/AudioSettings.html

Look in Time Manager. This document explains it and how it will be useful to you.

If you are working on Android, give up now :stuck_out_tongue:

Robertbu’s answer solved the problem. So glad I know about the function now. I can’t mark his comment as a correct answer so I’m quoting it here.

“Shot in the dark: Use InvokeRepeating() to fire off the sounds instead” - Robertbu