Unity VR Frames Per Second

Let’s talk about optimization and VR.

Optimization can be a broad subject to cover since so many variables can be attributed to how well a final product runs. One thing that can be focused on is a single unit of measurement. Frames Per Second.

FPS (Frames per second)

Frames per second are vital for any VR experience. If our application drops below 60 FPS, we risk giving our users simulation sickness. I’m incredibly prone to this sadly, but the good news is I’m forced to have good development practices so I don’t throw up!

Maintaining a high FPS is so important that Meta requires a minimum of 72 FPS for the Quest. Since FPS is the target, lets get it to display in our scene.

  • Add in the FPSDisplay prefab onto the Camera Offset
  • Select the FPSDiaplay  locate the Canvas component
    • Drag the Main Camera into the Render Camera slot
  • Expand the FPSDisplay and the Image underneath it
    • Locate the Display FPS script and set the Update Delay to 0.1

This will be the what we use to display our FPS. Since it’s for testing purposes, we set the Canvas to screen space – camera so it can easily track to our HMD as we look around.

Next is the script located on the FPSText.

Running through this script, we have five variables that will contain self explanatory information. The UpdateDelay variable will can be set in the editor to determine the rate that we update our FPS.

In the start function, we fetch our TMPro and also start off a coroutine that is responsible for updating our display. It will turn our text blue if we’re at or above the target FPS and a shrimp red if it’s below it. It then waits the update delay amount of time before updating again.

In the update function will call GenerateFramesPerSecond. It simply takes the current deltaTime and uses is to calculate the frames per second. Delta Time is simply the difference in time between the last from to the current frame. If we divide one by the current Delta Time, that will give us our frames per second.

And that’s really it! Now we can boot up our game and see our Frames per second in real time.

2 thoughts on “Unity VR Frames Per Second”

Comments are closed.