# Application lost focus event

**URL:** <https://forums.unrealengine.com/t/application-lost-focus-event/318146>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [May 11, 2015, 12:30am UTC](https://forums.unrealengine.com/t/application-lost-focus-event/318146 "2015-05-11T00:30:23Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alundra](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Alundra](https://forums.unrealengine.com/u/Alundra)\
**Post date:** [May 11, 2015, 12:30am UTC](https://forums.unrealengine.com/t/application-lost-focus-event/318146/1 "2015-05-11T00:30:23Z")

</div>

Hi,

I’m searching to set a pause menu and pause the game when lost the focus of the application but I don’t find a lost focus event.

Is it possible to know when the window lost focus ? How ?

Thanks

---

<div class="post-metadata">

**Author:** ![Pierdek](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pierdek](https://forums.unrealengine.com/u/Pierdek)\
**Post date:** [May 15, 2015, 3:26pm UTC](https://forums.unrealengine.com/t/application-lost-focus-event/318146/2 "2015-05-15T15:26:50Z")

</div>

I think you are looking for:

UGameViewportClient::LostFocus

You can derive from this class and make your own functionality, of course it needs to be done in c++.

---

<div class="post-metadata">

**Author:** ![Alundra](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Alundra](https://forums.unrealengine.com/u/Alundra)\
**Post date:** [May 15, 2015, 4:41pm UTC](https://forums.unrealengine.com/t/application-lost-focus-event/318146/3 "2015-05-15T16:41:01Z")

</div>

The engine must be changed and recompiled or a way exists to add an event without doing that ?

---

<div class="post-metadata">

**Author:** ![Pierdek](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pierdek](https://forums.unrealengine.com/u/Pierdek)\
**Post date:** [May 15, 2015, 4:46pm UTC](https://forums.unrealengine.com/t/application-lost-focus-event/318146/4 "2015-05-15T16:46:41Z")

</div>

Nope, only your c++ game module.

---

<div class="post-metadata">

**Author:** ![Alundra](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Alundra](https://forums.unrealengine.com/u/Alundra)\
**Post date:** [May 19, 2015, 2:26am UTC](https://forums.unrealengine.com/t/application-lost-focus-event/318146/5 "2015-05-19T02:26:31Z")

</div>

I added c++ code like that :

```
#pragma once

#include "Engine/GameViewportClient.h"
#include "MyGameViewportClient.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FLostFocusSignature);

/**
 * UMyGameViewportClient class.
 */
UCLASS()
class GAME_API UMyGameViewportClient : public UGameViewportClient
{
  GENERATED_BODY()

public:

  // Lost focus event.
  UPROPERTY(BlueprintAssignable, Category="LostFocus")
  FLostFocusSignature OnLostFocus;

  // Override lost focus function.
  virtual void LostFocus(FViewport* Viewport) override;
};

#include "Game.h"
#include "MyGameViewportClient.h"

void UMyGameViewportClient::LostFocus(FViewport* Viewport)
{
  UGameViewportClient::LostFocus(Viewport);
  OnLostFocus.Broadcast();
}

```

The problem is I don’t see the event in my game mode blueprint to call a pause game and show a pause menu, and I don’t find a node in blueprint to get the game viewport (maybe not possible). Is it possible to have a global event spawned to have access in game mode blueprint ?

---

<div class="post-metadata">

**Author:** ![Pierdek](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pierdek](https://forums.unrealengine.com/u/Pierdek)\
**Post date:** [May 19, 2015, 6:19am UTC](https://forums.unrealengine.com/t/application-lost-focus-event/318146/6 "2015-05-19T06:19:59Z")

</div>

Push your event throught gameinstance and the event will be globally, you can obtain game instance from BP. And you can obtain your game instance from UMyGameViewportClient.

---

<div class="post-metadata">

**Author:** ![Alundra](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Alundra](https://forums.unrealengine.com/u/Alundra)\
**Post date:** [May 19, 2015, 5:14pm UTC](https://forums.unrealengine.com/t/application-lost-focus-event/318146/7 "2015-05-19T17:14:15Z")

</div>

Ok, that works but sometimes the event is not sent, I don’t know why, actually not 100% safe to use.

```
#pragma once

#include "Engine/GameInstance.h"
#include "LostFocusGameInstance.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FLostFocusSignature);

/**
 * ULostFocusGameInstance class.
 */
UCLASS()
class GAME_API ULostFocusGameInstance : public UGameInstance
{
	GENERATED_BODY()

public:

	// Lost focus event.
	UPROPERTY(BlueprintAssignable, Category="LostFocus")
	FLostFocusSignature OnLostFocus;
};

#pragma once

#include "Engine/GameViewportClient.h"
#include "MyGameViewportClient.generated.h"

/**
 * UMyGameViewportClient class.
 */
UCLASS()
class GAME_API UMyGameViewportClient : public UGameViewportClient
{
	GENERATED_BODY()

public:

	// Override lost focus function.
	virtual void LostFocus(FViewport* Viewport) override;
};

#include "Game.h"
#include "MyGameViewportClient.h"
#include "LostFocusGameInstance.h"

void UMyGameViewportClient::LostFocus(FViewport* Viewport)
{
	UGameViewportClient::LostFocus(Viewport);
	static_cast<ULostFocusGameInstance*>(GameInstance)->OnLostFocus.Broadcast();
}
```

---

<div class="post-metadata">

**Author:** ![Kokuyouseki](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kokuyouseki](https://forums.unrealengine.com/u/Kokuyouseki)\
**Post date:** [February 3, 2019, 9:14am UTC](https://forums.unrealengine.com/t/application-lost-focus-event/318146/8 "2019-02-03T09:14:52Z")

</div>

Would be so nice to get an event like this - in blueprint…

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d3b64ca4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d3b64ca4](https://forums.unrealengine.com/u/anonymous_user_d3b64ca4)\
**Post date:** [December 29, 2020, 5:53pm UTC](https://forums.unrealengine.com/t/application-lost-focus-event/318146/9 "2020-12-29T17:53:46Z")

</div>

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](https://benui.ca/unreal/window-focus-change/)

---

<div class="post-metadata">

**Author:** ![Demonastraxx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Demonastraxx](https://forums.unrealengine.com/u/Demonastraxx)\
**Post date:** [November 13, 2024, 3:09pm UTC](https://forums.unrealengine.com/t/application-lost-focus-event/318146/10 "2024-11-13T15:09:59Z")

</div>

I know this is an old thread, but I haven’t seen anyone with a blueprint solution yet. After exploring plugins on fab, I found a node plugin that does the job!

The plugin is called **.exe Extension & Process Management** by Kibibyte.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/b/8/fb857ed3c6066a6ae2fe50cc7db2757b2bc1c471.png)

This is an example of a function that locks the mouse to the middle of the screen during gameplay and releases it when the window loses focus.

The plugin costs $20 for the personal license, which was worth it to me.
