# Is there a way to detect when the game goes to background?

**URL:** <https://forums.unrealengine.com/t/is-there-a-way-to-detect-when-the-game-goes-to-background/614990>\
**Category:** Blueprint\
**Tags:** Event-Handler, unreal-engine, UE4, Blueprint, question\
**Created:** [July 26, 2022, 9:12pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-when-the-game-goes-to-background/614990 "2022-07-26T21:12:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FranCalvente](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FranCalvente](https://forums.unrealengine.com/u/FranCalvente)\
**Post date:** [July 26, 2022, 9:12pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-when-the-game-goes-to-background/614990/1 "2022-07-26T21:12:11Z")

</div>

Hi all! I’m interested in calculate every second that the game goes inactive, I already have solved the part when I exit the game, I just save the Date Time and when I open again the game… BUT, I don’t know how to tell the game to save the Date Time when it goes to the background (not terminating the game). Is it actually possible?

---

<div class="post-metadata">

**Author:** ![barracius-AOne](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/barracius-aone/32/548049_2.png) [@barracius-AOne](https://forums.unrealengine.com/u/barracius-AOne)\
**Post date:** [July 26, 2022, 10:21pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-when-the-game-goes-to-background/614990/2 "2022-07-26T22:21:04Z")

</div>

Hi there @FranCalvente !

As I read on this thread, it’s not possible yet

> [@Test if Viewport is Minimized?](https://forums.unrealengine.com/t/test-if-viewport-is-minimized/317895):
>
> Hello, In my game I control the mouse position to be restricted to the window, if I minimize the game window, the mouse is still restricted to the bounds of the viewport. Is there a way in Blueprint to test if the Viewport is minimized or not? I know there is a function to set the focus to a viewport but I cannot seem to find a node that contains the words “active”, “focus”, “minimized” that achieves this task.

One thing you could do is maybe saving the DateTime in a file (or log) every X seconds or something like that

Another thing I read somewhere else, posted 2 alternatives

> <https://stackoverflow.com/questions/59617067/how-to-make-a-minimized-ue4-application-continue-to-run-in-the-background-or-min>

---

<div class="post-metadata">

**Author:** ![FranCalvente](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FranCalvente](https://forums.unrealengine.com/u/FranCalvente)\
**Post date:** [July 29, 2022, 6:45pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-when-the-game-goes-to-background/614990/3 "2022-07-29T18:45:18Z")

</div>

Thanks! that second option you mention worked for me! 🙂

---

<div class="post-metadata">

**Author:** ![Tonetfal](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tonetfal/32/1119420_2.png) [@Tonetfal](https://forums.unrealengine.com/u/Tonetfal)\
**Post date:** [September 16, 2024, 7:40pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-detect-when-the-game-goes-to-background/614990/4 "2024-09-16T19:40:04Z")

</div>

That’s how Lyra does it

```auto
// Listen for the event
FSlateApplication::Get().OnApplicationActivationStateChanged().AddUObject(this, &ThisClass::OnAppActivationStateChanged);

// Check whether it is minimized right now
FSlateApplication::IsInitialized() && !FSlateApplication::Get().IsActive()

```
