p.NumActiveChannels

p.NumActiveChannels

#Overview

name: p.NumActiveChannels

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.NumActiveChannels is to control the number of active channels in the Chaos physics system, which is part of Unreal Engine’s experimental physics framework.

This setting variable is primarily used in the Chaos subsystem, specifically within the ChaosResultsManager. It’s part of the experimental Chaos physics module in Unreal Engine.

The value of this variable is set through a console variable (CVar) named “p.NumActiveChannels”. It’s initialized with a default value stored in the DefaultNumActiveChannels variable, which is typically set to 1.

The p.NumActiveChannels variable interacts closely with DefaultNumActiveChannels. They share the same value, with DefaultNumActiveChannels serving as the initial value for p.NumActiveChannels.

Developers must be aware that changing this variable affects the number of active channels in the Chaos physics system. This can impact performance and simulation behavior, particularly in scenarios involving multi-threaded physics computations or when dealing with interpolation between physics states.

Best practices when using this variable include:

  1. Carefully consider the performance implications of increasing the number of active channels.
  2. Test thoroughly when modifying this value, as it can affect physics simulation results.
  3. Be cautious when changing this value at runtime, as it may require reinitializing parts of the physics system.

Regarding the associated variable DefaultNumActiveChannels:

The purpose of DefaultNumActiveChannels is to provide an initial value for p.NumActiveChannels and to serve as a reference point for the number of active channels in the Chaos physics system.

It’s used in the Chaos module, particularly in the ChaosResultsManager and in test scenarios (as seen in the HeadlessChaosTestRewind.cpp file).

The value of DefaultNumActiveChannels is typically set to 1, but it can be modified in code, especially for testing purposes.

DefaultNumActiveChannels interacts directly with p.NumActiveChannels, essentially serving as its default value.

Developers should be aware that changes to DefaultNumActiveChannels will affect the initial state of the physics system when it’s initialized. It’s particularly important in testing scenarios where different channel configurations need to be evaluated.

Best practices for DefaultNumActiveChannels include:

  1. Modifying it only when necessary, typically for testing or specific performance optimizations.
  2. Ensuring that any changes are properly reverted after tests to maintain consistent behavior in production environments.
  3. Documenting any non-standard values used in tests or specialized configurations to avoid confusion.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Framework/ChaosResultsManager.cpp:267

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:


	int32 DefaultNumActiveChannels = 1;
	FAutoConsoleVariableRef CVarNumActiveChannels(TEXT("p.NumActiveChannels"), DefaultNumActiveChannels, TEXT(""));

	FChaosResultsManager::FChaosResultsManager(FChaosMarshallingManager& InMarshallingManager)
		: MarshallingManager(InMarshallingManager)
		, NumActiveChannels(DefaultNumActiveChannels)
	{
		for(int32 Channel = 0; Channel < NumActiveChannels; ++Channel)

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Programs/HeadlessChaos/Private/HeadlessChaosTestRewind.cpp:4329

Scope (from outer to inner):

file
namespace    ChaosTest
function     GTEST_TEST

Source code excerpt:

	{
		Chaos::AsyncInterpolationMultiplier = 3.0f;
		int32 PrevNumActiveChannels = Chaos::DefaultNumActiveChannels;
		Chaos::DefaultNumActiveChannels = 2;
		//Have two moving particles, one in each channel to see that there's a delay in time on second channel
		TRewindHelper::TestDynamicSphere([](auto* Solver, FReal SimDt, int32 Optimization, auto Proxy, auto Sphere)
		{
			if (!Solver->IsUsingAsyncResults()) { return; }
			auto& Particle = Proxy->GetGameThreadAPI();
			Particle.SetV(FVec3(0, 0, 1));

#Loc: <Workspace>/Engine/Source/Programs/HeadlessChaos/Private/HeadlessChaosTestRewind.cpp:4381

Scope (from outer to inner):

file
namespace    ChaosTest
function     GTEST_TEST

Source code excerpt:

		});

		Chaos::DefaultNumActiveChannels = PrevNumActiveChannels;
	}


}

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Framework/ChaosResultsManager.cpp:266

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

	FAutoConsoleVariableRef CVarSecondChannelDelay(TEXT("p.SecondChannelDelay"), SecondChannelDelay, TEXT(""));

	int32 DefaultNumActiveChannels = 1;
	FAutoConsoleVariableRef CVarNumActiveChannels(TEXT("p.NumActiveChannels"), DefaultNumActiveChannels, TEXT(""));

	FChaosResultsManager::FChaosResultsManager(FChaosMarshallingManager& InMarshallingManager)
		: MarshallingManager(InMarshallingManager)
		, NumActiveChannels(DefaultNumActiveChannels)
	{
		for(int32 Channel = 0; Channel < NumActiveChannels; ++Channel)
		{
			Channels.Emplace(new FChaosResultsChannel(*this, Channel));
		}

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Public/Chaos/Framework/ChaosResultsManager.h:8

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

	
	extern FRealSingle SecondChannelDelay;
	extern int32 DefaultNumActiveChannels;

	struct FChaosRigidInterpolationData
	{
		FDirtyRigidParticleData Prev;
		FDirtyRigidParticleData Next;
	};