Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Time.fixedTime and family a float and not a double?

Tags:

unity3d

Just want know if I'm missing something. I'm from ObjC land where NSTimeInterval is a double, which gives "sub-millisecond precision within a range of 10,000 years". Compare this to Unity, which since it uses a float for time, starts to break down after a day (maybe even sooner). Math.Approximately(1 day, a day + 1 frame) returns true for example (whereas 1 hour vs 1 hour + 1 frame correctly returns false). I actually experienced this when I left my game open all night and came back to it, noticing strange behavior on things that were time dependent.

like image 221
Francisco Ryan Tolmasky I Avatar asked Apr 02 '14 07:04

Francisco Ryan Tolmasky I


1 Answers

Unity internally uses a double to track time. The double is converted to a float before being passed to user code.

This is largely because Unity uses floats in most other locations (floats are much better supported on a range of graphics cards/platforms).

Since Unity uses a double internally, you don't need to worry about it losing count / failing to increment time.

What you do need to worry about is that after the game has been running for a number of hours, the representable values become more and more sparse.

This can cause things that moved smoothly to start stuttering.

Personally, I tend to keep my own (float) and reset it to zero at some sensible interval, ideally when it makes no difference (which depends what you're using it for).

like image 130
Basic Avatar answered Nov 15 '22 09:11

Basic