p.DisableThreshold2

p.DisableThreshold2

#Overview

name: p.DisableThreshold2

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.DisableThreshold2 is to control the number of frames required for a rigid body to transition to a sleeping state in the Chaos physics system of Unreal Engine 5. This setting is primarily used in the physics simulation system, specifically for performance optimization by allowing objects to enter a dormant state when they become relatively static.

This setting variable is utilized by the Chaos physics module, which is part of Unreal Engine’s experimental features. It’s specifically used within the PBDRigidsEvolutionGBF (Position Based Dynamics Rigid Evolution Game and Battle Field) component of the Chaos system.

The value of this variable is set through the Unreal Engine’s console variable system. It’s initialized with a default value of 5, but can be changed at runtime using console commands or through project settings.

The p.DisableThreshold2 variable interacts directly with the DisableThreshold variable. They share the same value, with DisableThreshold being the actual variable used in the code, while p.DisableThreshold2 is the console-accessible name for this setting.

Developers should be aware that this variable affects the performance and behavior of physics simulations. A lower threshold will cause objects to enter the sleeping state more quickly, potentially improving performance but possibly at the cost of simulation accuracy. Conversely, a higher threshold will keep objects active longer, which may be more accurate but could impact performance.

Best practices when using this variable include:

  1. Carefully balancing performance needs with simulation accuracy.
  2. Testing different values to find the optimal setting for your specific game or application.
  3. Considering the types of objects in your scene and their expected behavior when adjusting this value.
  4. Being aware that changing this value can affect gameplay, especially in physics-heavy games.

Regarding the associated variable DisableThreshold:

The purpose of DisableThreshold is to directly store and provide access to the value set by p.DisableThreshold2 within the code. It’s used internally by the Chaos physics system to determine when to transition objects to a sleeping state.

This variable is used in the FPBDRigidsEvolutionGBF constructor to set the disable counter threshold for the island manager, which is a part of the physics simulation system that manages groups of interacting rigid bodies.

The value of DisableThreshold is set by the console variable system when p.DisableThreshold2 is modified.

Developers should be aware that modifying DisableThreshold directly in code won’t affect the console-accessible p.DisableThreshold2. Always use the console variable system to ensure consistency between these two variables.

Best practices for DisableThreshold include:

  1. Avoiding direct modification of this variable in code.
  2. Using the console variable system (p.DisableThreshold2) to change its value.
  3. Considering the impact on both performance and simulation accuracy when adjusting this value.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDRigidsEvolutionGBF.cpp:51

Scope (from outer to inner):

file
namespace    Chaos
namespace    CVars

Source code excerpt:


		int DisableThreshold = 5;
		FAutoConsoleVariableRef CVarDisableThreshold(TEXT("p.DisableThreshold2"), DisableThreshold, TEXT("Disable threshold frames to transition to sleeping"));

		int CollisionDisableCulledContacts = 0;
		FAutoConsoleVariableRef CVarDisableCulledContacts(TEXT("p.CollisionDisableCulledContacts"), CollisionDisableCulledContacts, TEXT("Allow the PBDRigidsEvolutionGBF collision constraints to throw out contacts mid solve if they are culled."));

		FRealSingle SmoothedPositionLerpRate = 0.3f;
		FAutoConsoleVariableRef CVarSmoothedPositionLerpRate(TEXT("p.Chaos.SmoothedPositionLerpRate"), SmoothedPositionLerpRate, TEXT("The interpolation rate for the smoothed position calculation. Used for sleeping."));

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDRigidsEvolutionGBF.cpp:50

Scope (from outer to inner):

file
namespace    Chaos
namespace    CVars

Source code excerpt:



		int DisableThreshold = 5;
		FAutoConsoleVariableRef CVarDisableThreshold(TEXT("p.DisableThreshold2"), DisableThreshold, TEXT("Disable threshold frames to transition to sleeping"));

		int CollisionDisableCulledContacts = 0;
		FAutoConsoleVariableRef CVarDisableCulledContacts(TEXT("p.CollisionDisableCulledContacts"), CollisionDisableCulledContacts, TEXT("Allow the PBDRigidsEvolutionGBF collision constraints to throw out contacts mid solve if they are culled."));

		FRealSingle SmoothedPositionLerpRate = 0.3f;
		FAutoConsoleVariableRef CVarSmoothedPositionLerpRate(TEXT("p.Chaos.SmoothedPositionLerpRate"), SmoothedPositionLerpRate, TEXT("The interpolation rate for the smoothed position calculation. Used for sleeping."));

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDRigidsEvolutionGBF.cpp:1089

Scope (from outer to inner):

file
namespace    Chaos
function     FPBDRigidsEvolutionGBF::FPBDRigidsEvolutionGBF

Source code excerpt:

	GetIslandManager().SetMaterialContainers(&PhysicsMaterials, &PerParticlePhysicsMaterials, &SolverPhysicsMaterials);
	GetIslandManager().SetGravityForces(&GravityForces);
	GetIslandManager().SetDisableCounterThreshold(DisableThreshold);

	SetParticleUpdatePositionFunction([this](const TParticleView<FPBDRigidParticles>& ParticlesInput, const FReal Dt)
	{
		ParticlesInput.ParallelFor([&](auto& Particle, int32 Index)
		{
			Particle.SetX(Particle.GetP());