How to get/calculate FPS in C++?

I’m developing a VR game and want to output my FPS or frame time in ms into a UTextRenderComponent. I can display text but cannot get or calculate the FPS. I could not find any way to that info from the engine so how do I calculate FPS inside a class derived from Pawn? I could use std::chrono but then I would need to know when a frame starts and ends.

I found the answer, it’s in the comments of an another answer:

I tried 1.0f / deltaTime in
OnTick() and it works!

maybe in the Ontick method on one of your Actors

Hey SurvivalMachine-

You may want to check the Engine class which has a number of FPS functions including Set/GetMaxFPS(). You should be able to use these functions to get information about FPS as necessary (UEngine | Unreal Engine Documentation ).


Thanks, but GetMaxFPS() always returns 0.

i am not sure but in theory

The ontick method is called each frame and it provides you a deltatime

the number of fps during that laps should be something like
1/deltatime right ?

of course it’s not a average record but you can do some stats with it

I tried 1.0f / deltaTime in OnTick() and it works!