- Home /
Time.time slower than real time on one computer
So I made a game for ludum dare where "note" objects spawn over time, in sync with a playing background music. It is critical that these notes are in sync with the music, so I base the spawning on Time.time.
This works fine, except for on one computer where notes are spawning too slow in relation to the music. After making experiments I found the following:
Music playback speed is correct on all computers (proven by recording sound with audacity)
Time.time counter is too slow, i.e. when real stop watch shows one minute, Time.time shows around 58 seconds. The error increases over time.
The same issue arises from summing up Time.deltaTime and also by using Time.fixedTime.
I have only seen the problem on one computer.
Problem is at least present in unity 4.2 and 4.3
Problem appears from within editor, from PC build and from web build (haven't tried any other platforms).
Time scale is correctly set to 1.
Tell me if I need to give you specs of my computer. So the problem seems to be that the internal time counter in unity is increasing too slow. Any ideas on what could be wrong?
Edit: My small game can be found at http://www.kongregate.com/games/Robinerd/polytonia if you want to see if you get the problem.
Answer by gregzo · Dec 21, 2013 at 06:56 AM
Hi,
Time.time returns the time at which the current frame started, and is not accurate as you found out. For precise musical timing, use AudioSettings.dspTime and play AudioClips with audio.PlayScheduled( double time ).
Thank you very much! using dspTime does indeed give me the correct ti$$anonymous$$g. Still curious about how Time.time can have an accumulating error of around 3% too much than actual time. But I marked this as resolved anyway since this is a workaround that solves the problem.
Your answer
Follow this Question
Related Questions
animation["name"].time is always zero? 3 Answers
Time.timeScale and Time.fixedDeltaTime 1 Answer
SmoothDamp smoothTime ignored! 1 Answer
Time.timeScale question 1 Answer
how to get smooth slow motion? 4 Answers