How to show FPS ingame?

Hi, I know how to show FPS in the editor, but how to show them while playing?

#Console Command

press ~

type

stat fps

#As a Console Command At Level Start

Rama

3 Likes

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 :slight_smile:

Checked. The console command works great, done just as in Kismet.

It’s possible to show FPS on mobile iOS/Android?

Updated:

  1. Open Level Blueprint from toolbar

  2. Add function ‘Execute Console Command’

  3. Enter ‘stat FPS’ in ‘Command’ field

  4. Attach ‘Event Begin Play’ to ‘Execute Console Command’

  5. Click ‘Compile’ in toolbar

  6. Run on device

6 Likes

‘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

1 Like

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.

48833-скриншот+2015-07-02+18.40.13.png

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;
    }
3 Likes

How did you know that ? :smiley: , It works.

Thank you, it’s very helpful!

  1. In the level blueprint, create an Event BeginPlay.
  2. Add an Execute Console Command.
  3. The command will be “Stats FPS”.
  4. 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.

1 Like

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

1 Like

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;
}
4 Likes

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.

1 Like

Thanks a lot man, you just solved my 1 week of search.

Much appreciated.

Thanks Again :slight_smile:

Wow…It works like charm