p.PhysicsRunsOnGT
p.PhysicsRunsOnGT
#Overview
name: p.PhysicsRunsOnGT
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
If true the physics thread runs on the game thread, but will still go wide on tasks like collision detection
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.PhysicsRunsOnGT is to control whether the physics simulation runs on the game thread or a separate physics thread in Unreal Engine 5’s Chaos physics system.
This setting variable is primarily used by the Chaos physics system, which is part of Unreal Engine’s experimental physics framework. It’s specifically referenced in the PhysicsSolverBase class, which is a core component of the Chaos physics simulation.
The value of this variable is set in multiple ways:
- It’s initialized to 0 by default.
- It can be changed via the console variable system (CVarPhysicsRunsOnGT).
- It can be overridden by passing the “-PhysicsRunsOnGT” command-line argument when launching the game.
The associated variable PhysicsRunsOnGT interacts directly with p.PhysicsRunsOnGT. They share the same value and are used interchangeably in the code.
Developers must be aware that:
- Setting this variable to 1 will cause physics simulations to run on the game thread, which could impact performance, especially in complex scenes.
- Even when running on the game thread, certain physics tasks like collision detection will still be parallelized.
- This setting can significantly affect the behavior and performance of the physics system.
Best practices when using this variable include:
- Use it primarily for debugging purposes or when troubleshooting physics-related issues.
- Be cautious about enabling it in production builds, as it may impact performance.
- Consider the trade-offs between physics accuracy and performance when deciding whether to use this setting.
Regarding the associated variable PhysicsRunsOnGT: It serves the same purpose as p.PhysicsRunsOnGT and is used internally within the Chaos physics system. It directly affects the thread selection for physics tasks, as seen in the FPhysicsSolverAdvanceTask::GetDesiredThread() function. When PhysicsRunsOnGT is 0, physics tasks run on a separate thread; when it’s non-zero, they run on the game thread. Developers should treat this variable with the same considerations as p.PhysicsRunsOnGT, as they are effectively the same setting.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Framework/PhysicsSolverBase.cpp:82
Scope (from outer to inner):
file
namespace Chaos
Source code excerpt:
int32 PhysicsRunsOnGT = 0;
FAutoConsoleVariableRef CVarPhysicsRunsOnGT(TEXT("p.PhysicsRunsOnGT"), PhysicsRunsOnGT, TEXT("If true the physics thread runs on the game thread, but will still go wide on tasks like collision detection"));
ENamedThreads::Type FPhysicsSolverProcessPushDataTask::GetDesiredThread()
{
return CPrio_FPhysicsTickTask.Get();
}
#Associated Variable and Callsites
This variable is associated with another variable named PhysicsRunsOnGT
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Framework/PhysicsSolverBase.cpp:81
Scope (from outer to inner):
file
namespace Chaos
Source code excerpt:
);
int32 PhysicsRunsOnGT = 0;
FAutoConsoleVariableRef CVarPhysicsRunsOnGT(TEXT("p.PhysicsRunsOnGT"), PhysicsRunsOnGT, TEXT("If true the physics thread runs on the game thread, but will still go wide on tasks like collision detection"));
ENamedThreads::Type FPhysicsSolverProcessPushDataTask::GetDesiredThread()
{
return CPrio_FPhysicsTickTask.Get();
}
ENamedThreads::Type FPhysicsSolverAdvanceTask::GetDesiredThread()
{
return PhysicsRunsOnGT == 0 ? CPrio_FPhysicsTickTask.Get() : ENamedThreads::GameThread;
}
void FPhysicsSolverProcessPushDataTask::ProcessPushData()
{
using namespace Chaos;
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Framework/PhysicsSolverBase.cpp:247
Scope (from outer to inner):
file
namespace Chaos
function FPhysicsSolverBase::FPhysicsSolverBase
Source code excerpt:
UE_LOG(LogChaos, Verbose, TEXT("FPhysicsSolverBase::AsyncDt:%f"), IsUsingAsyncResults() ? AsyncDt : -1);
//If user is running with -PhysicsRunsOnGT override the cvar (doing it here to avoid parsing every time task is scheduled)
if(FParse::Param(FCommandLine::Get(), TEXT("PhysicsRunsOnGT")))
{
PhysicsRunsOnGT = 1;
}
}
#if CHAOS_DEBUG_NAME
void FPhysicsSolverBase::SetDebugName(const FName& Name)
{