How to show FPS ingame?

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