p.Chaos.Collision.UnionBVH.UseOptimizedCountLeafObjects

p.Chaos.Collision.UnionBVH.UseOptimizedCountLeafObjects

#Overview

name: p.Chaos.Collision.UnionBVH.UseOptimizedCountLeafObjects

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.UnionBVH.UseOptimizedCountLeafObjects is to enable or disable an optimized method for counting leaf objects in the Bounding Volume Hierarchy (BVH) used in the Chaos physics engine’s collision detection system.

This setting variable is primarily used in the Chaos physics engine, which is part of Unreal Engine’s experimental physics system. Specifically, it’s used in the collision detection subsystem, particularly in the implementation of Implicit Object Unions and BVHs.

The value of this variable is set using an FAutoConsoleVariableRef, which means it can be changed at runtime through console commands. It’s initialized to true by default.

This variable interacts closely with the associated variable bChaosImplicitBVHOptimizedCountLeafObjects. They share the same value and are used interchangeably in the code.

Developers must be aware that this is part of an experimental system and may be subject to changes or removal in future versions. The comment “// @todo: remove this when tested” suggests that this might be a temporary feature for testing purposes.

Best practices when using this variable include:

  1. Monitor its impact on performance in your specific use case.
  2. Be prepared for potential changes in future engine versions.
  3. Use it in conjunction with other Chaos physics settings for optimal results.

Regarding the associated variable bChaosImplicitBVHOptimizedCountLeafObjects:

Its purpose is the same as p.Chaos.Collision.UnionBVH.UseOptimizedCountLeafObjects - to control the use of an optimized method for counting leaf objects in the BVH.

It’s used in the Chaos physics engine’s collision detection system, specifically in the FImplicitBVH::CountLeafObjects function.

The value is set by the console variable p.Chaos.Collision.UnionBVH.UseOptimizedCountLeafObjects.

When this variable is true, it enables a potentially more efficient method of counting leaf objects in the hierarchy. This could have performance implications, especially for complex hierarchies.

Developers should be aware that this optimization might behave differently for different types of object hierarchies. It’s important to profile and test with your specific use cases to ensure it provides the expected benefits.

Best practices include thoroughly testing the performance impact of enabling or disabling this optimization in your specific scenarios, and being prepared for potential changes as the Chaos physics system evolves.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/ImplicitObjectUnion.cpp:36

Scope (from outer to inner):

file
namespace    Chaos
namespace    CVars

Source code excerpt:

		// @todo: remove this when tested
		bool bChaosImplicitBVHOptimizedCountLeafObjects = true;
		FAutoConsoleVariableRef CVarChaosImplicitBVHOptimizedCountLeafObjects(TEXT("p.Chaos.Collision.UnionBVH.UseOptimizedCountLeafObjects"), bChaosImplicitBVHOptimizedCountLeafObjects, TEXT(""));

	}

inline FAABB3 CalculateObjectsBounds(const TArrayView<FImplicitObjectPtr>& Objects)
{
	if (Objects.IsEmpty())

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/ImplicitObjectBVH.cpp:9

Scope (from outer to inner):

file
namespace    Chaos
namespace    CVars

Source code excerpt:

		extern FRealSingle ChaosUnionBVHSplitBias;

		extern bool bChaosImplicitBVHOptimizedCountLeafObjects;
	}

	namespace Private
	{
		static_assert(sizeof(FImplicitBVHObject) == 72, "FImplicitBVHObject was packed to avoid any padding in it");

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/ImplicitObjectBVH.cpp:45

Scope (from outer to inner):

file
namespace    Chaos
namespace    Private
function     int32 FImplicitBVH::CountLeafObjects

Source code excerpt:

			// Count the objects in the hierarchy
			int32 NumObjects = 0;
			if (CVars::bChaosImplicitBVHOptimizedCountLeafObjects)
			{
				for (const Chaos::FImplicitObjectPtr& RootObject : InRootObjects)
				{
					NumObjects += RootObject->CountLeafObjectsInHierarchy();
				}
			}

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/ImplicitObjectUnion.cpp:35

Scope (from outer to inner):

file
namespace    Chaos
namespace    CVars

Source code excerpt:

		// Use the new FImplicitObject::CountLeafObjectsInHierarchy to count leaf objects
		// @todo: remove this when tested
		bool bChaosImplicitBVHOptimizedCountLeafObjects = true;
		FAutoConsoleVariableRef CVarChaosImplicitBVHOptimizedCountLeafObjects(TEXT("p.Chaos.Collision.UnionBVH.UseOptimizedCountLeafObjects"), bChaosImplicitBVHOptimizedCountLeafObjects, TEXT(""));

	}

inline FAABB3 CalculateObjectsBounds(const TArrayView<FImplicitObjectPtr>& Objects)
{
	if (Objects.IsEmpty())