Application lost focus event

if someone having issues with UGameViewportClient::LostFocus
then another possible solution is:

// the following code is qouted from: https://benui.ca/unreal/window-focus-change/
void ABUIPlayerController::BeginPlay()
{
	FSlateApplication::Get().OnApplicationActivationStateChanged()
		.AddUObject( this, &ABUIPlayerController::OnWindowFocusChanged );
}

void ABUIPlayerController::OnWindowFocusChanged( bool bIsFocused )
{
// Don't pause in the editor, it's annoying
#if !WITH_EDITOR
	if ( bIsFocused )
	{
		// Unlimit game FPS
		GEngine->SetMaxFPS( 0 );

		// Unpause the game
		// MyHUD->SetPause( false );
	}
	else
	{
		// Reduce FPS to max 10 while in the background
		GEngine->SetMaxFPS( 10.0f );

		// Pause the game, using your "show pause menu" function
		// MyHUD->SetPause( true );
	}
#endif
}

thanks to Ben @ Pause Game When Window Loses Focus · ben🌱ui

4 Likes