p.Chaos.Thread.WaitThreshold

p.Chaos.Thread.WaitThreshold

#Overview

name: p.Chaos.Thread.WaitThreshold

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

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Chaos.Thread.WaitThreshold is to control the maximum wait time for the game thread to synchronize with the physics thread in Unreal Engine’s Chaos physics system.

This setting variable is primarily used by the Chaos physics system, which is part of Unreal Engine’s experimental physics module. It’s specifically utilized in the ChaosSolversModule, which handles the synchronization between the game thread and the dedicated physics thread.

The value of this variable is set through the console variable system in Unreal Engine. It’s defined as a TAutoConsoleVariable with a default value of 0, which actually corresponds to a default wait time of 16ms as mentioned in the description.

The associated variable CVarDedicatedThreadSyncThreshold directly interacts with p.Chaos.Thread.WaitThreshold. They share the same value and are used interchangeably in the code.

Developers must be aware that this variable affects the balance between physics accuracy and game performance. A higher threshold allows more time for physics calculations but may introduce latency in game responsiveness. Conversely, a lower threshold ensures quicker game thread progression but might result in using less accurate physics results.

Best practices when using this variable include:

  1. Adjusting it based on the specific needs of your game, considering the complexity of physics simulations and desired responsiveness.
  2. Testing different values to find the optimal balance between physics accuracy and performance for your specific use case.
  3. Monitoring performance metrics when changing this value to ensure it doesn’t negatively impact overall game performance.

Regarding the associated variable CVarDedicatedThreadSyncThreshold:

The purpose of CVarDedicatedThreadSyncThreshold is to provide a programmatic way to access and modify the wait threshold for physics synchronization.

It’s used within the Chaos physics system, specifically in the ChaosSolversModule, to determine how long the game thread should wait for physics calculations before proceeding.

The value of this variable is set through the console variable system and is initialized with the same parameters as p.Chaos.Thread.WaitThreshold.

This variable directly interacts with p.Chaos.Thread.WaitThreshold, effectively serving as its C++ representation within the engine code.

Developers should be aware that modifying CVarDedicatedThreadSyncThreshold will have the same effect as changing p.Chaos.Thread.WaitThreshold. It’s used in the SyncTask function to determine the maximum wait time for acquiring a lock on the physics thread.

Best practices for using CVarDedicatedThreadSyncThreshold include:

  1. Using it in code when you need to programmatically access or modify the wait threshold.
  2. Considering its impact on both physics accuracy and game thread responsiveness when adjusting its value.
  3. Using it in conjunction with other Chaos physics settings to fine-tune the physics simulation behavior in your game.

#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:31

Scope: file

Source code excerpt:


TAutoConsoleVariable<int32> CVarDedicatedThreadSyncThreshold(
	TEXT("p.Chaos.Thread.WaitThreshold"),
	0,
	TEXT("Desired wait time in ms before the game thread stops waiting to sync physics and just takes the last result. (default 16ms)")
);

namespace Chaos
{

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/ChaosSolversModule.cpp:30

Scope: file

Source code excerpt:

	TEXT("Desired update rate of the dedicated physics thread in Hz/FPS (Default 60.0f)"));

TAutoConsoleVariable<int32> CVarDedicatedThreadSyncThreshold(
	TEXT("p.Chaos.Thread.WaitThreshold"),
	0,
	TEXT("Desired wait time in ms before the game thread stops waiting to sync physics and just takes the last result. (default 16ms)")
);

namespace Chaos

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/ChaosSolversModule.cpp:169

Scope (from outer to inner):

file
function     void FChaosSolversModule::SyncTask

Source code excerpt:

#if 0
	// Hard lock the physics thread before syncing our data
	FChaosScopedPhysicsThreadLock ScopeLock(bForceBlockingSync ? MAX_uint32 : (uint32)(CVarDedicatedThreadSyncThreshold.GetValueOnGameThread()));

	// This will either get the results because physics finished, or fall back on whatever physics last gave us
	// to allow the game thread to continue on without stalling.
	PhysicsInnerTask->SyncProxiesFromCache(ScopeLock.DidGetLock());

	// Update stats if necessary