- Home /
Is Time.deltaTime consistent across different platforms/devices?
The game I'm working on keeps track of the time it takes to complete a level, which is sent to the Leaderboards. The plan is to just have a global Leaderboard across all platforms since that'll result in more scores/competition/whatever.
Currently, I'm keeping track of game time using the following code:
void Update()
{
CompletionTime += Time.deltaTime;
}
A few questions have popped up that I'm not entirely sure about:
Will this be handled exactly the same across all platforms? FPS doesn't change on a per-platform basis does it?
What happens if the game starts running slow (slower device, framerate glitch, etc.)? A longer frame will result in a greater deltaTime so that should also remain consistent whether the game runs buttery smooth or really slow.
Is Time.deltaTime appropriate for this? Should I just grab the 'Time.time' when the game completes instead?
IN answer to your question 1,
lol, Time.deltaTime is not only different on every platform, it is different every frame. it is completely different all the time everywhere and always.
To achieve what you are trying to do, very simply use (3) or a variant thereof
note that Update should have utterly nothing to do with what you're trying to do. you'd simply do something, like, make a note of the time of day when the user starts a level, and make a note when she crosses the finish line (or, whatever). it's just that simple.
(Very generally, never use Update() at all, unless it's some arcane system related task.)
FPS doesn't change on a per-platform basis does it?
Of course it does. Every platform has different hardware capabilities.
it is completely different all the time everywhere and always.
Well, not if you use vsync and can maintain that framerate....
Answer by GerryM · Dec 01, 2012 at 09:08 PM
1) no, FPS does differ hugely among devices, even on the same device it will differ.
2) if your games runs slower deltaTime will increase, but as there are equally less calls to the update function the time measurement will be the same. That's basically the idea of deltaTime, to adjust for different framerates.
3) Time.time would be much more adequate, no need to waste resources on deltaTime in the update function, as you don't really need it. Check this answer.