Hi, I know how to show FPS in the editor, but how to show them while playing?
Thanks, Rama, youâre everywhere! Apparently in some keyboards itâs the ^ key. Is there a way to make it also show when playing in âSelected Viewportâ?
youâre welcome!
please check mark my reply above if it answered your question, and try to comment on my answer to keep everything in one place
Checked. The console command works great, done just as in Kismet.
Itâs possible to show FPS on mobile iOS/Android?
Updated:
-
Open Level Blueprint from toolbar
-
Add function âExecute Console Commandâ
-
Enter âstat FPSâ in âCommandâ field
-
Attach âEvent Begin Playâ to âExecute Console Commandâ
-
Click âCompileâ in toolbar
-
Run on device
âstat unitâ may be also useful.
This will show game and render thread times.
old thread but in case anyone was wondering: you can also access the console commands in mobile with 4 finger tap
I did not find the standard function to get the frame rate in C++ so I get them this way:
Tick execute in second so many times how many frames per second is displayed, so you can count how many times was called tick per second using a timer.
void AGameCharacter::BeginPlay()
{
Super::BeginPlay();
FTimerHandle FPSTimerHandle;
GetWorld()->GetTimerManager().SetTimer(FPSTimerHandle, this, &AGameCharacter::ShowFrameRate, 1.f, true);
}
int FPS = 0;
void AGameCharacter::Tick( float DeltaTime )
{
Super::Tick(DeltaTime);
FPS++;
}
void AGameCharacter::ShowFrameRate()
{
GEngine->AddOnScreenDebugMessage(0, 1.f, FColor::Yellow, "FPS: " + FString::FromInt(FPS) + " ms: " + FString::SanitizeFloat(FApp::GetDeltaTime() * 1000));
FPS = 0;
}
How did you know that ? , It works.
Thank you, itâs very helpful!
- In the level blueprint, create an Event BeginPlay.
- Add an Execute Console Command.
- The command will be âStats FPSâ.
- Connect the Event BeginPlay with the Execute Console Command.
In the toolbar, hit âLaunchâ to test it, because if you will play it in the editor, you wonât be able to see the FPS.
Hi !
Can you tell me how to stop this timer after 30 seconds in showframerate() function.
As a variant, you can create another timer, so that he called 1 time after 30 seconds launch.
GetWorld()->GetTimerManager().SetTimer(SomeTimerHandle, this, &AGameCharacter::StopShowFrameRate, 30.f, false);
StopShowFrameRate()
{
GetWorld()->GetTimerManager().ClearTimer(FPSTimerHandle);
}
the command should be âstat fpsâ, not âstats fpsâ.
You can get stat fps data directly from engine. It stores in global engine variables GAverageFPS and GAverageMS (defined in UnrealEngine.cpp for use with extern). It calculates every engine tick by the next algorithm:
// Calculate the average frame time via continued averaging.
static double LastTime = 0;
double CurrentTime = FPlatformTime::Seconds();
float FrameTime = (CurrentTime - LastTime) * 1000;
// A 3/4, 1/4 split gets close to a simple 10 frame moving average
GAverageMS = GAverageMS * 0.75f + FrameTime * 0.25f;
LastTime = CurrentTime;
// Calculate average framerate.
GAverageFPS = 1000.f / GAverageMS;
Iâm looking now for a stock functionality to get it in blueprint, but if there is no such, you can create yours.
Example:
float UMyFunctionLibrary::GetAverageFPS()
{
extern ENGINE_API float GAverageFPS;
return GAverageFPS;
}
I am wondering if I need to get GAverageFPS from a plugin, then how should I do to get this variable?
Exactly the same way as I showed above. Type âextern ENGINE_API float GAverageFPS;â inside the pluginâs function. Here is no difference.
Thanks a lot man, you just solved my 1 week of search.
Much appreciated.
Thanks Again
WowâŚIt works like charm