- Home /
How to create an accurate timer in Unity?
Hey, I'm looking for a way to make a high-accuracy and reliable timer in Unity. I'm looking to use it for psychology research, because I'm relatively good at Unity compared to other programs, but this kind of accuracy is beyong my skill level.
I'm looking for at least 5 decimals after seconds, that is precision to the 0.00001 second. (preferably even 6 decimals but 5 is enough) Of course, it also has to be reliable accross machines.
I've looked at a few things but the accuracy isn't even close to this so I'd appreciate whatever ideas you might have.
Thanks!
For the most part, code execution in Unity is framerate dependent and running threads can be a pain. As you likely know C#, you would likely be better off writing a C# app for the task.
Did you find any solution for that @Lesockmonkey ? I need it for similar research purposes too. Thanks!
Answer by Xarbrough · Sep 19, 2019 at 09:05 AM
Timing with high accuracy is a larger issue in itself, not so much Unity specific, I'd say. You can star your own thread in Unity and start counting time, but you will always run into troubles caused by performance hiccups caused by the operating system, for example. And of course the timer itself is not of much unless you can start and stop it accurately, but user input and graphical UI will need to sync to the main thread in most common applications, so you probably need specific hardware support, e.g. a button or LED lights which trigger at high precision.
All in all I wonder, why you would need this precision for you experiment. I by no means know much about the field, but for example, human reaction time is much more in the region of 0.2 seconds, and this is precision we can simply to in Unity either with a high and stable framerate on the main thread or with a timer running on the second thread, and simply accepting some error when starting and stopping the timer via UI.
Your answer
Follow this Question
Related Questions
timer not ticking down 2 Answers
How do I make a Countdown Timer in Minutes and Seconds only 1 Answer
How to make this display milliseconds? 3 Answers
Timer ends game 1 Answer
How do I stop 'timeSinceLevelLoad' without pausing entire game? 2 Answers