- Home /
Framerate counter
I have made/found a simple framerate counter, but the weird thing is the result, it is not the same as the stats give in the fps section.
var updateInterval : float = 0.5;
private var frames : int; // Frames drawn over the interval
private var timeleft : float; // Left time for current interval
private var accum : float;
var highestFPS : float;
var fps : float;
function Update() {
timeleft -= Time.deltaTime;
frames++;
accum += Time.timeScale/Time.deltaTime;
if(timeleft <= 0.0) {
fps = accum/frames;
if (fps > highestFPS) {
highestFPS = fps;
}
accum = 0.0f;
timeleft = updateInterval;
frames = 0;
}
}
Answer by gribbly · Oct 29, 2014 at 09:00 PM
Try doing it in FixedUpdate().
If the differences in results are minor (like 29.9 instead of 29.8), it's probably just rounding somewhere in the chain and nothing to worry about.
If it's a major difference (like 60.0 vs. 30.0) then you probably screwed up your code =]
The difference is something between 10 and 20 frames per second and putting it in a FixedUpdate made the fps stay solid at 50.
I found out that the framerate showed by the stats screen isn't the "real fps" so there was nothing wrong with my script.
Your answer
Follow this Question
Related Questions
Real elapsed time since frame begin 1 Answer
Is it possible to move time per rendered frame? 0 Answers
How to measure time independently on frame rate? 2 Answers
Is it a bad practice to change the timescale for the whole game? 1 Answer
Is there a way to speed up the game more than 100 times? 1 Answer