Search code examples
c#unity-game-engineframe-rate

Calculating the frame-rate in a Unity scene


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?

Solution

  • 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.