Game window minimized but game still running at 100%

Does anyone know of a way to have a game respond like the editor so that when the application is minimized, it stops rendering?

Even just an event minimized would do the trick since I can at least disabled world rendering.

Any ideas?

The “editor sleeps in background” behavior is a sleep function in the main loop, which you can control by returning true from ShouldUseIdleMode().

		bool bIdleMode;
			// Idle mode prevents ticking and rendering completely
			bIdleMode = ShouldUseIdleMode();
			if (bIdleMode)
				// Yield CPU time

You have control over this with the t.IdleWhenNotForeground cvar:

	static const auto CVarIdleWhenNotForeground = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("t.IdleWhenNotForeground"));

It will avoid idling while a level is loading, though, to make sure level load doesn’t slow down a lot.

How did I find this? I opened up EngineLoop.cpp (by adding a FEngineLoop dummy reference and pressing F12) and searched for “Sleep” in the file. The highlight ShouldUseIdleMode() and press F12 again.

Thanks Jwatte for taking a stab at this. Unfortunately, this method has some unwanted behaviour since the game stops ticking altogether (not just rendering) and it isn’t limited to when the game is minimized.

In an ideal scenario, I want to disable world rendering when the window is minimized. If I lose focus on the window but it’s still visible, I want the game to continue to run normally.

Ideally, a minimize/maximize event would do the trick.

You wanted what the editor does. This is what the editor does!

Assuming that your simulation does proper sub-stepping, you will still get enough simulation ticks.

If you need something more custom than that, I hope the place I pointed at will be a good place to start for where to add the custom code.

When looking at the task manager it seemed like the the editor was reacting differently between a window minimize and a window focus loss. I guess not. That’s quite unfortunate because a “disable world rendering” still seems to outperform the idle mode on every resource.

Thanks for pointing out this method.