Pause everything when game not in focus?

I’d like to pause the game when it’s not in focus by the player. For example alt-tabbing or minimizing would trigger a function that stops the time until the window is back in focus.

How can this be achieved, preferably in BP? I can’t find a function that returns if window is in focus or not. Best idea I have is to have a transparent widget cover the screen and check if that is in focus. Any advice?

The console command t.IdleWhenNotForeground=1 will lower framerate and CPU usage when you’ve alt-tabbed out. You can then maybe use frame time to determine if you’re idling for a BP only solution.

Otherwise you can get a C++ function to detect lost focus, see this question for details.

Is it possible to get a bool out of this command? I’m having trouble implementing this method.

For anyone interested, after enable-ing this you can get the FPS logged by dividing the DeltaTime on the Tick event by 1. In order to do that you have to have the blueprint set as Tickable even when Paused if you want to pause/unpause on lost focus.

I guess no news on this huh.
So far the closest I got without going too deep, checking if mouse location is 0:0 :slight_smile: Searching didn’t work out too well either, this is the best discussion about the problem I have found so far.

But seriously, a simple event or blueprint node for checking if the game is in focus or not would be very welcome - Okay, I bet they have enough on their plates as is but I would really appretiate something like that.

Hi, I just encountered the same problem here. I was just wondering the same thing for my android project. It is really annoying that so much timing issues occur when the game is minimised. I know this is old post but I hope to help. For me I printed a string to get the delta time, and compared when it was and wasn’t in focus. I saw that when out of focus my game was running delta seconds at .3 and when in focus its always bellow 0.1. So I did a little thing and it works for me. You need the ability to un pause when game is returned to screen. My UI had that ability already in my HUD widget.