p.Chaos.Collision.UseGJK2

p.Chaos.Collision.UseGJK2

#Overview

name: p.Chaos.Collision.UseGJK2

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

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Chaos.Collision.UseGJK2 is to control whether the Chaos physics engine uses a new index-less GJK (Gilbert-Johnson-Keerthi) algorithm for collision detection. This setting variable is part of the collision system within the Chaos physics engine in Unreal Engine 5.

The Chaos physics engine, which is part of Unreal Engine’s experimental features, relies on this setting variable. Specifically, it’s used in the collision detection subsystem of Chaos.

The value of this variable is set through the Unreal Engine console variable system. It’s initialized as false in the source code, but can be changed at runtime using console commands.

This variable interacts directly with its associated boolean variable bChaos_Collision_UseGJK2. They share the same value, with the console variable p.Chaos.Collision.UseGJK2 controlling the value of bChaos_Collision_UseGJK2.

Developers must be aware that this variable is marked as a temporary feature that “should be removed once soaked for a bit”. It was enabled on June 7, 2022, which suggests it’s a relatively new feature that may still be under testing or refinement.

Best practices when using this variable include:

  1. Thoroughly testing collision behavior with both values (true and false) to ensure your game’s physics behave correctly in both cases.
  2. Being prepared for potential removal of this feature in future engine versions.
  3. Monitoring performance impacts when enabling or disabling this feature.

Regarding the associated variable bChaos_Collision_UseGJK2:

The purpose of bChaos_Collision_UseGJK2 is to act as the internal boolean flag that determines whether to use the new index-less GJK algorithm in the actual collision detection code.

This variable is used directly in the collision detection logic within the Chaos physics engine. It’s checked in functions like GJKContactPointMargin and GJKContactPointSameSpace to determine which version of the GJK algorithm to use.

The value of bChaos_Collision_UseGJK2 is set by the console variable p.Chaos.Collision.UseGJK2. It’s initialized as false in the source code.

Developers should be aware that changing this variable will directly affect the collision detection algorithm used in their physics simulations. It’s important to test thoroughly when modifying this value to ensure desired physics behavior is maintained.

Best practices include using this in conjunction with the console variable for easier runtime toggling and debugging, and being prepared for potential changes or removal of this feature in future engine versions.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionOneShotManifolds.cpp:113

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

	// @todo(chaos): This should be removed once soaked for a bit (enabled 7 June 2022)
	bool bChaos_Collision_UseGJK2 = false;
	FAutoConsoleVariableRef CVarChaos_Collision_UseGJK2(TEXT("p.Chaos.Collision.UseGJK2"), bChaos_Collision_UseGJK2, TEXT(""));

	bool bChaos_Collision_OneSidedTriangleMesh = true;
	bool bChaos_Collision_OneSidedHeightField = true;
	FAutoConsoleVariableRef CVarChaos_Collision_OneSidedTriangleMesh(TEXT("p.Chaos.Collision.OneSidedTriangleMesh"), bChaos_Collision_OneSidedTriangleMesh, TEXT(""));
	FAutoConsoleVariableRef CVarChaos_Collision_OneSidedHeightfield(TEXT("p.Chaos.Collision.OneSidedHeightField"), bChaos_Collision_OneSidedHeightField, TEXT(""));

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionOneShotManifolds.cpp:112

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

	// Whether to use the new index-less GJK. 
	// @todo(chaos): This should be removed once soaked for a bit (enabled 7 June 2022)
	bool bChaos_Collision_UseGJK2 = false;
	FAutoConsoleVariableRef CVarChaos_Collision_UseGJK2(TEXT("p.Chaos.Collision.UseGJK2"), bChaos_Collision_UseGJK2, TEXT(""));

	bool bChaos_Collision_OneSidedTriangleMesh = true;
	bool bChaos_Collision_OneSidedHeightField = true;
	FAutoConsoleVariableRef CVarChaos_Collision_OneSidedTriangleMesh(TEXT("p.Chaos.Collision.OneSidedTriangleMesh"), bChaos_Collision_OneSidedTriangleMesh, TEXT(""));
	FAutoConsoleVariableRef CVarChaos_Collision_OneSidedHeightfield(TEXT("p.Chaos.Collision.OneSidedHeightField"), bChaos_Collision_OneSidedHeightField, TEXT(""));

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionOneShotManifolds.cpp:514

Scope (from outer to inner):

file
namespace    Chaos
namespace    Collisions
function     FContactPoint GJKContactPointMargin

Source code excerpt:


			bool bHaveContact = false;
			if (bChaos_Collision_UseGJK2)
			{
				bHaveContact = GJKPenetrationWarmStartable2(AWithMargin, BWithMargin, BToATM, Penetration, ClosestA, ClosestB, NormalA, NormalB, VertexIndexA, VertexIndexB, InOutGjkWarmStartData, OutMaxMarginDelta, GJKEpsilon, EPAEpsilon);
			}
			else
			{
				bHaveContact = GJKPenetrationWarmStartable(AWithMargin, BWithMargin, BToATM, Penetration, ClosestA, ClosestB, NormalA, NormalB, VertexIndexA, VertexIndexB, InOutGjkWarmStartData, OutMaxMarginDelta, GJKEpsilon, EPAEpsilon);

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionOneShotManifolds.cpp:551

Scope (from outer to inner):

file
namespace    Chaos
namespace    Collisions
function     FContactPoint GJKContactPointSameSpace

Source code excerpt:


			bool bHaveContact = false;
			if (bChaos_Collision_UseGJK2)
			{
				bHaveContact = GJKPenetrationSameSpace2(A, B, Penetration, ClosestA, ClosestB, Normal, VertexIndexA, VertexIndexB, OutMaxMarginDelta, InitialGJKDir, GJKEpsilon, EPAEpsilon);
			}
			else
			{
				bHaveContact = GJKPenetrationSameSpace(A, B, Penetration, ClosestA, ClosestB, Normal, VertexIndexA, VertexIndexB, OutMaxMarginDelta, InitialGJKDir, GJKEpsilon, EPAEpsilon);