Calculating the frame-rate in a Unity scene

Joana picture Joana · Aug 27, 2015 · Viewed 11k times · Source

I'm making a project with Augmented Reality, using Unity and Vuforia extensions. I'm new to C#, but I was looking for a method similar to ARToolKit's getFrame(), and I'm really not finding anything.

My questions are:

  1. Is it necessary that I can calculate the frame-rate that my scene is operating at?
  2. Which scene object should i use to track the frame-rate?

Answer

maksymiuk picture maksymiuk · Aug 27, 2015

Thats as simple as:

public float avgFrameRate;

public void Update()
{
    avgFrameRate = Time.frameCount / Time.time;
}

Put this code in any MonoBehaviour and attatch it to any GameObject in the scene hierarchy.

Please note: this will only give you an average frame-rate. For a more current frame-rate, other answers have addressed effective ways of accomplishing that.