p.Chaos.CCD.AllowedDepthBoundsScale

p.Chaos.CCD.AllowedDepthBoundsScale

#Overview

name: p.Chaos.CCD.AllowedDepthBoundsScale

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

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Chaos.CCD.AllowedDepthBoundsScale is to control the amount of penetration allowed after rewinding to the Time of Impact (TOI) in Continuous Collision Detection (CCD) calculations within the Chaos physics system of Unreal Engine 5.

This setting variable is primarily used in the Chaos physics subsystem, specifically in the CCD module. It’s an important parameter for fine-tuning collision detection and response in physics simulations.

The value of this variable is set to 0.2f by default, as seen in the code snippet. It can be modified at runtime through the console variable system, allowing for dynamic adjustments during development or gameplay.

The associated variable CCDAllowedDepthBoundsScale interacts directly with p.Chaos.CCD.AllowedDepthBoundsScale, as they share the same value. This variable is used in various parts of the CCD calculation process.

Developers must be aware that:

  1. This value must be less than CCDEnableThresholdBoundsScale to function correctly.
  2. It affects the precision of collision detection and can impact performance and visual accuracy of physics simulations.
  3. Setting this value to 0 or a very small number may lead to more precise collisions but could potentially impact performance.

Best practices when using this variable include:

  1. Carefully balancing between performance and accuracy. Lower values provide more precise collisions but may be more computationally expensive.
  2. Testing different values to find the optimal setting for your specific use case.
  3. Consider adjusting this value dynamically based on the importance of precise collisions in different game scenarios.

Regarding the associated variable CCDAllowedDepthBoundsScale:

Developers should be mindful of how changes to this variable can affect the overall physics simulation and test thoroughly when modifying its 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/CCDUtilities.cpp:35

Scope (from outer to inner):

file
namespace    Chaos
namespace    CVars

Source code excerpt:

		// Determines how much penetration CCD leaves after rewinding to TOI. Must be less than CCDEnableThresholdBoundsScale
		Chaos::FRealSingle CCDAllowedDepthBoundsScale = 0.2f;
		FAutoConsoleVariableRef CVarCCDAllowedDepthBoundsScale(TEXT("p.Chaos.CCD.AllowedDepthBoundsScale"), CCDAllowedDepthBoundsScale, TEXT("When rolling back to TOI, allow (smallest bound's extent) * AllowedDepthBoundsScale, instead of rolling back to exact TOI w/ penetration = 0."));

		// When enabled, CCD TOI is set to the first contact which gets a depth of (CCDAllowedDepthBoundsScale * Object Size).
		// When disabled, CCD will find the first contact, ignoreing the rest, and then fix the TOI to result in the specified depth.
		// This fixes the issue where (when disabled) we would set TOI to some value that would leave us penetrating another (later) object. This
		// could happen when colliding with the floor near the base of a ramp for example.
		bool bCCDNewTargetDepthMode = true;

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CCDUtilities.cpp:34

Scope (from outer to inner):

file
namespace    Chaos
namespace    CVars

Source code excerpt:


		// Determines how much penetration CCD leaves after rewinding to TOI. Must be less than CCDEnableThresholdBoundsScale
		Chaos::FRealSingle CCDAllowedDepthBoundsScale = 0.2f;
		FAutoConsoleVariableRef CVarCCDAllowedDepthBoundsScale(TEXT("p.Chaos.CCD.AllowedDepthBoundsScale"), CCDAllowedDepthBoundsScale, TEXT("When rolling back to TOI, allow (smallest bound's extent) * AllowedDepthBoundsScale, instead of rolling back to exact TOI w/ penetration = 0."));

		// When enabled, CCD TOI is set to the first contact which gets a depth of (CCDAllowedDepthBoundsScale * Object Size).
		// When disabled, CCD will find the first contact, ignoreing the rest, and then fix the TOI to result in the specified depth.
		// This fixes the issue where (when disabled) we would set TOI to some value that would leave us penetrating another (later) object. This
		// could happen when colliding with the floor near the base of a ramp for example.
		bool bCCDNewTargetDepthMode = true;
		FAutoConsoleVariableRef  CVarCCDNewTargetDepthMode(TEXT("p.Chaos.CCD.NewTargetDepthMode"), bCCDNewTargetDepthMode, TEXT("Find the first contact with that results in a penetration of (CCDAllowedDepthBoundsScale*Size) as opposed to the first contact"));

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CCDUtilities.cpp:427

Scope (from outer to inner):

file
namespace    Chaos
function     void FCCDManager::ApplyIslandSweptConstraints2

Source code excerpt:

			// We don't normally apply impulses in the CCD phase because we leave on overlap for the main solver to handle. However if the
			// settings are such that this won't happen, we must apply the impulse here. CCD impulses assume point masses and no rotations or friction are applied.
			const bool bApplyImpulse = (CVars::CCDAllowedDepthBoundsScale <= 0);
			if (bApplyImpulse)
			{
				ApplyImpulse(CCDConstraint);
			}

			if (CCDParticle0)

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Collision/PBDCollisionConstraint.cpp:21

Scope (from outer to inner):

file
namespace    Chaos
namespace    CVars

Source code excerpt:

	{
		extern FRealSingle CCDEnableThresholdBoundsScale;
		extern FRealSingle CCDAllowedDepthBoundsScale;
	}

	extern bool bChaos_Collision_EnableManifoldGJKInject;
	extern bool bChaos_Collision_EnableManifoldGJKReplace;

	FRealSingle Chaos_Manifold_MatchPositionTolerance = 0.3f;		// Fraction of object size position tolerance

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Collision/PBDCollisionConstraint.cpp:452

Scope (from outer to inner):

file
namespace    Chaos
function     void FPBDCollisionConstraint::InitCCDThreshold

Source code excerpt:

		// NOTE: this can be zero but if it is we will get very poor behaviour because there will be
		// nothing for the contact resolution to do since we fully depenetrated in the CCD rewind.
		CCDTargetPenetration = MinBounds * CVars::CCDAllowedDepthBoundsScale;
	}

	void FPBDCollisionConstraint::Activate()
	{
		Flags.bIsCurrent = true;
		Flags.bDisabled = false;