Inaccurate Values For Time.time and Time.deltaTime.

Hi,

I need to be able to accurately run a function every second and be able to flag an error if this is not the case.

I have tried InvokeRepeating(“InvokeRepeatingTimeTest”, 0, 1.0f); and this works fine until I lock the thread up (intentionally as a test) either using System.Threading.Thread.Sleep or a large for loop. In both cases, even though there is several seconds delay between debug statements, time is always +1 second (1.02, 2.02, 3.02…) and deltaTime is always 0.2 seconds.

I then tried using a time >= Mathf.FloorToInt(lastTime) + 1 in Update() rather than using InvokeRepeating and got exactly the same result.

Is there a way that I can get an accurate idea of the time since the last call or does Unity simply go “It has been a long time, best call InvokeRepeatingTimeTest and pretend that I have done it in time”?

Try the “standard” C# classes, e.g. Stopwatch: