t.IdleWhenNotForeground
t.IdleWhenNotForeground
#Overview
name: t.IdleWhenNotForeground
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Prevents the engine from taking any CPU or GPU time while not the foreground app.
It is referenced in 5
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of t.IdleWhenNotForeground is to control whether the engine should reduce CPU and GPU usage when the application is not in the foreground.
This setting variable is primarily used by the engine’s core systems, specifically the engine loop and resource management. It’s referenced in the LaunchEngineLoop.cpp file, which is part of the runtime launch module.
The value of this variable is set through the console variable system. It’s initialized with a default value of 0 in the ConsoleManager.cpp file.
The associated variable CVarIdleWhenNotForeground interacts directly with t.IdleWhenNotForeground. They share the same value and purpose.
Developers must be aware that enabling this variable (setting it to 1) will cause the engine to significantly reduce its resource usage when the application loses focus. This can be beneficial for reducing system load but may affect the game’s behavior when running in the background.
Best practices for using this variable include:
- Leave it disabled (0) for games that need to continue processing at full speed even when not in focus.
- Enable it (1) for applications where background processing is not critical, to improve system resource management.
- Consider the implications on multiplayer games or games with real-time elements that need to continue updating even when not in focus.
Regarding the associated variable CVarIdleWhenNotForeground:
The purpose of CVarIdleWhenNotForeground is the same as t.IdleWhenNotForeground - to control the engine’s resource usage when not in focus.
This variable is used in the engine’s core systems, particularly in the FEngineLoop::ShouldUseIdleMode() function, which determines whether the engine should enter an idle state.
The value of CVarIdleWhenNotForeground is set through the console variable system, initialized in ConsoleManager.cpp.
CVarIdleWhenNotForeground directly interacts with t.IdleWhenNotForeground, as they represent the same setting.
Developers should be aware that this variable is used in conditional checks to determine the engine’s behavior when not in focus. It’s particularly important in windowed mode applications.
Best practices for using CVarIdleWhenNotForeground are the same as for t.IdleWhenNotForeground, as they are essentially the same variable. Developers should consider the performance and gameplay implications of enabling or disabling this feature based on their specific application requirements.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/HAL/ConsoleManager.cpp:3829
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarIdleWhenNotForeground(
TEXT("t.IdleWhenNotForeground"), 0,
TEXT("Prevents the engine from taking any CPU or GPU time while not the foreground app."),
ECVF_Cheat);
static TAutoConsoleVariable<int32> CVarSetVSyncEnabled(
TEXT("r.VSync"),
0,
#Loc: <Workspace>/Engine/Plugins/Experimental/Avalanche/Source/AvalancheMedia/Private/Playback/AvaPlaybackServer.cpp:150
Scope (from outer to inner):
file
function void FAvaPlaybackServer::Init
Source code excerpt:
// Prevent throttling and idling.
if (IConsoleVariable* IdleWhenNotForeground = IConsoleManager::Get().FindConsoleVariable(TEXT("t.IdleWhenNotForeground")))
{
IdleWhenNotForeground->Set(0);
}
FCoreDelegates::OnEndFrame.AddSP(this, &FAvaPlaybackServer::Tick);
#Loc: <Workspace>/Engine/Source/Runtime/Launch/Private/LaunchEngineLoop.cpp:5354
Scope (from outer to inner):
file
function bool FEngineLoop::ShouldUseIdleMode
Source code excerpt:
bool FEngineLoop::ShouldUseIdleMode() const
{
static const auto CVarIdleWhenNotForeground = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("t.IdleWhenNotForeground"));
bool bIdleMode = false;
// Yield cpu usage if desired
if (FApp::IsGame()
&& FPlatformProperties::SupportsWindowedMode()
&& CVarIdleWhenNotForeground->GetValueOnGameThread()
#Associated Variable and Callsites
This variable is associated with another variable named CVarIdleWhenNotForeground
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/HAL/ConsoleManager.cpp:3828
Scope: file
Source code excerpt:
ECVF_Scalability | ECVF_RenderThreadSafe);
static TAutoConsoleVariable<int32> CVarIdleWhenNotForeground(
TEXT("t.IdleWhenNotForeground"), 0,
TEXT("Prevents the engine from taking any CPU or GPU time while not the foreground app."),
ECVF_Cheat);
static TAutoConsoleVariable<int32> CVarSetVSyncEnabled(
TEXT("r.VSync"),
#Loc: <Workspace>/Engine/Source/Runtime/Launch/Private/LaunchEngineLoop.cpp:5354
Scope (from outer to inner):
file
function bool FEngineLoop::ShouldUseIdleMode
Source code excerpt:
bool FEngineLoop::ShouldUseIdleMode() const
{
static const auto CVarIdleWhenNotForeground = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("t.IdleWhenNotForeground"));
bool bIdleMode = false;
// Yield cpu usage if desired
if (FApp::IsGame()
&& FPlatformProperties::SupportsWindowedMode()
&& CVarIdleWhenNotForeground->GetValueOnGameThread()
&& !FApp::HasFocus())
{
bIdleMode = true;
}
#if BUILD_EMBEDDED_APP