p.ClothPhysics.UseTaskThread

p.ClothPhysics.UseTaskThread

#Overview

name: p.ClothPhysics.UseTaskThread

This variable is created as a Console Variable (cvar).

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.ClothPhysics.UseTaskThread is to control whether cloth physics simulations in Unreal Engine 5 run on a separate task thread or on the game thread. This setting variable is primarily used for the cloth simulation system, which is part of the physics and rendering subsystems.

The Unreal Engine subsystem that relies on this setting variable is the cloth simulation system, specifically within the ChaosClothAsset plugin and the Engine’s skeletal mesh component physics.

The value of this variable is set as a console variable, with a default value of 1 (true). It can be changed at runtime through the console or programmatically.

This variable interacts closely with CVarEnableClothPhysicsUseTaskThread, which is an associated variable that shares the same value and purpose.

Developers must be aware that changing this variable affects the threading behavior of cloth simulations. When set to 1, cloth simulations run on a separate task thread, potentially improving performance by offloading work from the game thread. When set to 0, simulations run on the game thread, which might be preferable in certain debugging scenarios or for specific synchronization requirements.

Best practices when using this variable include:

  1. Consider the overall performance impact when deciding whether to run cloth simulations on a separate thread or the game thread.
  2. Be aware of potential synchronization issues when running cloth simulations on a separate thread.
  3. Use this setting in conjunction with other cloth-related settings for optimal performance and visual quality.

Regarding the associated variable CVarEnableClothPhysicsUseTaskThread:

The purpose of CVarEnableClothPhysicsUseTaskThread is identical to p.ClothPhysics.UseTaskThread. It controls whether cloth physics simulations run on a separate task thread or on the game thread.

This variable is used in the Engine’s skeletal mesh component physics system. It’s defined and set in the same file as p.ClothPhysics.UseTaskThread.

The value of this variable is also set as a console variable, with the same default value of 1 (true).

CVarEnableClothPhysicsUseTaskThread directly interacts with the FParallelClothTask class, determining which thread the cloth simulation tasks will run on.

Developers should be aware that this variable is used internally by the engine to make threading decisions for cloth simulation tasks.

Best practices for using this variable are the same as those for p.ClothPhysics.UseTaskThread, as they serve the same purpose and are essentially two ways of accessing the same setting.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SkeletalMeshComponentPhysics.cpp:50

Scope: file

Source code excerpt:

TAutoConsoleVariable<int32> CVarEnableClothPhysics(TEXT("p.ClothPhysics"), 1, TEXT("If 1, physics cloth will be used for simulation."), ECVF_Scalability);

static TAutoConsoleVariable<int32> CVarEnableClothPhysicsUseTaskThread(TEXT("p.ClothPhysics.UseTaskThread"), 1, TEXT("If 1, run cloth on the task thread. If 0, run on game thread."));
static TAutoConsoleVariable<int32> CVarClothPhysicsTickWaitForParallelClothTask(TEXT("p.ClothPhysics.WaitForParallelClothTask"), 0, TEXT("If 1, always wait for cloth task completion in the Cloth Tick function. If 0, wait at end-of-frame updates instead if allowed by component settings"));

static TAutoConsoleVariable<bool> CVarClothTeleportOverride(TEXT("p.Cloth.TeleportOverride"), false, TEXT("Force console variable teleport override values over skeletal mesh properties.\n Default: false."));
static TAutoConsoleVariable<bool> CVarClothResetAfterTeleport(TEXT("p.Cloth.ResetAfterTeleport"), true, TEXT("Require p.Cloth.TeleportOverride. Reset the clothing after moving the clothing position (called teleport).\n Default: true."));
static TAutoConsoleVariable<float> CVarClothTeleportDistanceThreshold(TEXT("p.Cloth.TeleportDistanceThreshold"), 300.f, TEXT("Require p.Cloth.TeleportOverride. Conduct teleportation if the character's movement is greater than this threshold in 1 frame.\n Zero or negative values will skip the check.\n Default: 300."));
static TAutoConsoleVariable<float> CVarClothTeleportRotationThreshold(TEXT("p.Cloth.TeleportRotationThreshold"), 0.f, TEXT("Require p.Cloth.TeleportOverride. Rotation threshold in degrees, ranging from 0 to 180.\n Conduct teleportation if the character's rotation is greater than this threshold in 1 frame.\n Zero or negative values will skip the check.\n Default 0."));

#Loc: <Workspace>/Engine/Plugins/ChaosClothAsset/Source/ChaosClothAssetEngine/Private/ChaosClothAsset/ClothSimulationProxy.cpp:62

Scope (from outer to inner):

file
namespace    UE::Chaos::ClothAsset
class        class FClothSimulationProxyParallelTask
function     static ENamedThreads::Type GetDesiredThread

Source code excerpt:

		static ENamedThreads::Type GetDesiredThread()
		{
			static IConsoleVariable* const CVarClothPhysicsUseTaskThread = IConsoleManager::Get().FindConsoleVariable(TEXT("p.ClothPhysics.UseTaskThread"));

			if (CVarClothPhysicsUseTaskThread && CVarClothPhysicsUseTaskThread->GetBool())
			{
				return CPrio_ClothSimulationProxyParallelTask.Get();
			}
			return ENamedThreads::GameThread;

#Associated Variable and Callsites

This variable is associated with another variable named CVarEnableClothPhysicsUseTaskThread. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SkeletalMeshComponentPhysics.cpp:50

Scope: file

Source code excerpt:

TAutoConsoleVariable<int32> CVarEnableClothPhysics(TEXT("p.ClothPhysics"), 1, TEXT("If 1, physics cloth will be used for simulation."), ECVF_Scalability);

static TAutoConsoleVariable<int32> CVarEnableClothPhysicsUseTaskThread(TEXT("p.ClothPhysics.UseTaskThread"), 1, TEXT("If 1, run cloth on the task thread. If 0, run on game thread."));
static TAutoConsoleVariable<int32> CVarClothPhysicsTickWaitForParallelClothTask(TEXT("p.ClothPhysics.WaitForParallelClothTask"), 0, TEXT("If 1, always wait for cloth task completion in the Cloth Tick function. If 0, wait at end-of-frame updates instead if allowed by component settings"));

static TAutoConsoleVariable<bool> CVarClothTeleportOverride(TEXT("p.Cloth.TeleportOverride"), false, TEXT("Force console variable teleport override values over skeletal mesh properties.\n Default: false."));
static TAutoConsoleVariable<bool> CVarClothResetAfterTeleport(TEXT("p.Cloth.ResetAfterTeleport"), true, TEXT("Require p.Cloth.TeleportOverride. Reset the clothing after moving the clothing position (called teleport).\n Default: true."));
static TAutoConsoleVariable<float> CVarClothTeleportDistanceThreshold(TEXT("p.Cloth.TeleportDistanceThreshold"), 300.f, TEXT("Require p.Cloth.TeleportOverride. Conduct teleportation if the character's movement is greater than this threshold in 1 frame.\n Zero or negative values will skip the check.\n Default: 300."));
static TAutoConsoleVariable<float> CVarClothTeleportRotationThreshold(TEXT("p.Cloth.TeleportRotationThreshold"), 0.f, TEXT("Require p.Cloth.TeleportOverride. Rotation threshold in degrees, ranging from 0 to 180.\n Conduct teleportation if the character's rotation is greater than this threshold in 1 frame.\n Zero or negative values will skip the check.\n Default 0."));

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SkeletalMeshComponentPhysics.cpp:3656

Scope (from outer to inner):

file
class        class FParallelClothTask
function     static ENamedThreads::Type GetDesiredThread

Source code excerpt:

	static ENamedThreads::Type GetDesiredThread()
	{
		if (CVarEnableClothPhysicsUseTaskThread.GetValueOnAnyThread() != 0)
		{
			return CPrio_FParallelClothTask.Get();
		}
		return ENamedThreads::GameThread;
	}
	static ESubsequentsMode::Type GetSubsequentsMode()