Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Time accuracy

Discussion in 'Editor & General Support' started by VanEl, May 5, 2014.

  1. VanEl

    VanEl

    Joined:
    May 5, 2014
    Posts:
    1
    Hi everybody!

    I know that there have been a few discussions already about the time accuracy and how to improve it.

    Until now I'm not really familiar with Unity. However, I'm a psychologist and want to use Unity for a psychological study. It'll be a reaction time experiment. What means that I need time differences with high accuracy, cause the differences can be in the millisecond range.

    so my question:

    How accurate can Unity be related to the millisecond range? What is possible?

    thanks for your help.
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,741
    If you're using Unity's methods, they can go as detailed as frames. Obviously, if you need to time something based in milliseconds, this is not going to work. You're likely to top out around 100-200 frames per second.

    You might have better luck if you use whatever input methods C# has natively (if any?) in conjunction with System.DateTime.Now.Ticks for the most detailed measurement possible. I don't know C# well enough to know what options this entails, but that's where you'll have to search for your answer, at least.
     
  3. Diviner

    Diviner

    Joined:
    May 8, 2010
    Posts:
    677
    Depends on how you measure time. It's not a floating point accuracy issue, since floats are perfectly fine in measuring values in the triple digits. First it depends on what calculations you do with these values (and how many decimals these calculations output) and then it depends on how you update your time. If done so on an by-frame case, you're forced to round down each frame's time estimate to the minimum deltaTime, which can completely ruin your final results.

    I would launch a second thread, frame rate independent, and measure time in that thread instead of relying on the Update.
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,741
    Even if you have a timer running in a second thread (and that probably is a good idea), you will definitely still have to figure out how to get input in that thread... without relying on any of Unity's Input class, as I'm fairly certain those only update once a frame.