- Home /
Is there an equivalent of Time.frameCount for physics updates?
I have a game where I'm running the physics at a very high rate (i.e. I have set my "Fixed Timestep" value to be very small). It is normal and expected behaviour for me to have several FixedUpdate
calls per Update
.
Time.frameCount
gives me a value of how many Update
have happened since the game start. Is there an equivalent that tells me how many FixedUpdate
calls have happened?
Obviously it's easy enough to write my own. I was just wondering if there was a built-in value.
Answer by Geoxion · Mar 07, 2016 at 03:35 PM
No there isn't. Like you said, you need to write it yourself. But there might be a way to calculate it with this: https://docs.unity3d.com/ScriptReference/Time-fixedTime.html
int fixedUpdateCount = Mathf.RountToInt(Time.fixedTime / Time.fixedDeltaTime);
I wouldn't feel comfortable using the floating point division to give me an accurate answer.
Thanks for confir$$anonymous$$g that there's nothing built-in.
Then you'll have to have a counter that increases every fixedupdate
Shouldn't Time.fixedTime
be used ins$$anonymous$$d of Time.realtimeSinceStartup
?
Yes, this would give a much more exact result. There's no problem using floating point numbers here. Until the error get into the whole numbers the game / application would need to run about 46 days in a row. See my table over here. So you can savely use $$anonymous$$athf.RountToInt on the result.
Since Geoxion wasn't online for about a year I will edit the answer and change it to fixedTime.