p.Chaos.DedicatedThreadEnabled
p.Chaos.DedicatedThreadEnabled
#Overview
name: p.Chaos.DedicatedThreadEnabled
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Enables a dedicated physics task/thread for Chaos tasks.0: Disabled1: Enabled
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.Chaos.DedicatedThreadEnabled is to control whether a dedicated physics task/thread is enabled for Chaos tasks in Unreal Engine 5’s physics system.
This setting variable is primarily used by the Chaos physics system, which is part of Unreal Engine’s experimental physics module. Based on the callsites, it’s clear that this variable is utilized within the ChaosSolversModule.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1 (enabled) but can be changed at runtime through console commands or configuration files.
The associated variable CVarChaosThreadEnabled directly interacts with p.Chaos.DedicatedThreadEnabled. They share the same value and purpose.
Developers should be aware that this variable affects the threading model of the Chaos physics system. When enabled (set to 1), it allows for a dedicated thread for physics calculations, which can potentially improve performance by offloading physics computations from the main game thread.
Best practices when using this variable include:
- Consider the target hardware when deciding whether to enable or disable this feature. More powerful systems may benefit from the dedicated thread, while less powerful systems might perform better with it disabled.
- Profile your game’s performance with this setting both enabled and disabled to determine the optimal configuration for your specific use case.
- Be aware of potential threading issues that may arise when enabling a dedicated physics thread, such as race conditions or synchronization problems.
Regarding the associated variable CVarChaosThreadEnabled:
The purpose of CVarChaosThreadEnabled is identical to p.Chaos.DedicatedThreadEnabled. It’s the C++ representation of the console variable that controls the dedicated physics thread for Chaos tasks.
This variable is used within the ChaosSolversModule to determine if the persistent task (dedicated thread) is enabled. The IsPersistentTaskEnabled() function directly uses this variable to check its state.
The value of CVarChaosThreadEnabled is set through the TAutoConsoleVariable template, which allows it to be modified via console commands or configuration files.
Developers should be aware that this variable is accessed on the game thread (as seen in the GetValueOnGameThread() call), which means any changes to it will be reflected in the next frame.
Best practices for using CVarChaosThreadEnabled include:
- Use the provided FChaosSolversModule::IsPersistentTaskEnabled() function to check the state of this variable, rather than accessing it directly.
- Be cautious when changing this value at runtime, as it may have implications on ongoing physics calculations.
- Consider exposing this setting in your game’s options menu to allow users to optimize performance based on their hardware capabilities.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/ChaosSolversModule.cpp:19
Scope: file
Source code excerpt:
TAutoConsoleVariable<int32> CVarChaosThreadEnabled(
TEXT("p.Chaos.DedicatedThreadEnabled"),
1,
TEXT("Enables a dedicated physics task/thread for Chaos tasks.")
TEXT("0: Disabled")
TEXT("1: Enabled"));
TAutoConsoleVariable<Chaos::FRealSingle> CVarDedicatedThreadDesiredHz(
#Associated Variable and Callsites
This variable is associated with another variable named CVarChaosThreadEnabled
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/ChaosSolversModule.cpp:18
Scope: file
Source code excerpt:
#include "Chaos/PhysicalMaterials.h"
TAutoConsoleVariable<int32> CVarChaosThreadEnabled(
TEXT("p.Chaos.DedicatedThreadEnabled"),
1,
TEXT("Enables a dedicated physics task/thread for Chaos tasks.")
TEXT("0: Disabled")
TEXT("1: Enabled"));
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/ChaosSolversModule.cpp:152
Scope (from outer to inner):
file
function bool FChaosSolversModule::IsPersistentTaskEnabled
Source code excerpt:
bool FChaosSolversModule::IsPersistentTaskEnabled() const
{
return CVarChaosThreadEnabled.GetValueOnGameThread() == 1;
}
bool FChaosSolversModule::IsPersistentTaskRunning() const
{
return bPersistentTaskSpawned;
}