p.CollisionRestitutionThreshold

p.CollisionRestitutionThreshold

#Overview

name: p.CollisionRestitutionThreshold

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.CollisionRestitutionThreshold is to set a threshold for collision restitution in the physics simulation system of Unreal Engine 5. It is specifically used in the Chaos physics engine, which is part of the experimental features in UE5.

This setting variable is primarily used in the Chaos namespace, which is part of the Experimental Chaos module. It’s specifically referenced in the PBDCollisionConstraints.cpp file, indicating its importance in particle-based dynamics (PBD) collision handling.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of -1.0f, but can be overridden at runtime using the console command system.

The p.CollisionRestitutionThreshold interacts closely with the CollisionRestitutionThresholdOverride variable. They share the same value, with CollisionRestitutionThresholdOverride serving as the actual storage for the threshold value.

Developers must be aware that this variable is in units of acceleration, not velocity or distance. Also, it only takes effect if its value is greater than or equal to 0, as indicated by the condition check in the UpdateConstraintMaterialProperties function.

Best practices when using this variable include:

  1. Only set it to non-negative values when you want to override the default behavior.
  2. Be cautious when changing this value, as it can significantly affect the physics simulation’s behavior.
  3. Use it in conjunction with other collision-related variables for fine-tuning physics behavior.

Regarding the associated variable CollisionRestitutionThresholdOverride:

The purpose of CollisionRestitutionThresholdOverride is to store the actual value of the collision restitution threshold. It serves as the backing variable for the p.CollisionRestitutionThreshold console variable.

This variable is used directly in the UpdateConstraintMaterialProperties function of the FPBDCollisionConstraints class. When its value is greater than or equal to 0, it overrides the MaterialRestitutionThreshold value.

The value of CollisionRestitutionThresholdOverride is set through the console variable system, allowing for runtime modification of the physics behavior.

Developers should be aware that while p.CollisionRestitutionThreshold is the console variable name, CollisionRestitutionThresholdOverride is the actual variable used in the code. Changes to one will affect the other.

Best practices for CollisionRestitutionThresholdOverride include:

  1. Treat it as read-only within your code, modifying it only through the console variable system.
  2. When debugging physics issues, check both the console variable and this override variable to ensure they’re in sync.
  3. Remember that negative values will be ignored in the physics calculations, so only positive values will have an effect.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDCollisionConstraints.cpp:67

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:


	FRealSingle CollisionRestitutionThresholdOverride = -1.0f;
	FAutoConsoleVariableRef CVarDefaultCollisionRestitutionThreshold(TEXT("p.CollisionRestitutionThreshold"), CollisionRestitutionThresholdOverride, TEXT("Collision restitution threshold override if >= 0 (units of acceleration)"));

	int32 CollisionCanAlwaysDisableContacts = 0;
	FAutoConsoleVariableRef CVarCollisionCanAlwaysDisableContacts(TEXT("p.CollisionCanAlwaysDisableContacts"), CollisionCanAlwaysDisableContacts, TEXT("Collision culling will always be able to permanently disable contacts"));

	int32 CollisionCanNeverDisableContacts = 0;
	FAutoConsoleVariableRef CVarCollisionCanNeverDisableContacts(TEXT("p.CollisionCanNeverDisableContacts"), CollisionCanNeverDisableContacts, TEXT("Collision culling will never be able to permanently disable contacts"));

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDCollisionConstraints.cpp:66

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

	FAutoConsoleVariableRef CVarDefaultCollisionRestitution(TEXT("p.DefaultCollisionRestitution"), DefaultCollisionRestitution, TEXT("Collision restitution default value if no materials are found."));

	FRealSingle CollisionRestitutionThresholdOverride = -1.0f;
	FAutoConsoleVariableRef CVarDefaultCollisionRestitutionThreshold(TEXT("p.CollisionRestitutionThreshold"), CollisionRestitutionThresholdOverride, TEXT("Collision restitution threshold override if >= 0 (units of acceleration)"));

	int32 CollisionCanAlwaysDisableContacts = 0;
	FAutoConsoleVariableRef CVarCollisionCanAlwaysDisableContacts(TEXT("p.CollisionCanAlwaysDisableContacts"), CollisionCanAlwaysDisableContacts, TEXT("Collision culling will always be able to permanently disable contacts"));

	int32 CollisionCanNeverDisableContacts = 0;
	FAutoConsoleVariableRef CVarCollisionCanNeverDisableContacts(TEXT("p.CollisionCanNeverDisableContacts"), CollisionCanNeverDisableContacts, TEXT("Collision culling will never be able to permanently disable contacts"));

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDCollisionConstraints.cpp:515

Scope (from outer to inner):

file
namespace    Chaos
function     void FPBDCollisionConstraints::UpdateConstraintMaterialProperties

Source code excerpt:

			MaterialRestitution = CollisionRestitutionOverride;
		}
		if (CollisionRestitutionThresholdOverride >= 0.0f)
		{
			MaterialRestitutionThreshold = CollisionRestitutionThresholdOverride;
		}
		if (CollisionAngularFrictionOverride >= 0)
		{
			MaterialStaticFriction = CollisionAngularFrictionOverride;
		}
		if (CollisionBaseFrictionImpulseOverride >= 0)