p.ForceDisableAsyncPhysics

p.ForceDisableAsyncPhysics

#Overview

name: p.ForceDisableAsyncPhysics

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.ForceDisableAsyncPhysics is to provide a way to forcibly disable asynchronous physics simulation in Unreal Engine 5, regardless of other settings. This variable is part of the physics system, specifically the Chaos physics engine.

The Unreal Engine subsystem that relies on this setting variable is the Chaos physics module, which is part of the experimental Chaos framework. This can be seen from the file paths and namespaces in the provided code snippets.

The value of this variable is set through a console variable (CVar) named “p.ForceDisableAsyncPhysics”. It’s initialized to 0 by default, meaning asynchronous physics is not forcibly disabled unless explicitly set.

This variable interacts with other physics-related variables, particularly:

  1. UseAsyncInterpolation
  2. AsyncDt

Developers must be aware that:

  1. Setting this variable to a non-zero value will disable asynchronous physics regardless of other settings.
  2. This variable directly affects the behavior of the IsUsingAsyncResults() function in the FPhysicsSolverBase class.
  3. It can impact performance and simulation accuracy, as it forces synchronous physics calculations.

Best practices when using this variable include:

  1. Use it mainly for debugging or troubleshooting purposes.
  2. Be cautious about enabling it in production builds, as it may negatively impact performance.
  3. Consider the implications on other physics-related settings and behaviors when modifying this variable.

Regarding the associated variable ForceDisableAsyncPhysics:

The purpose of ForceDisableAsyncPhysics is the same as p.ForceDisableAsyncPhysics. It’s the actual int32 variable that stores the value set by the console variable.

This variable is used directly in the Chaos physics module, specifically in the FPhysicsSolverBase class.

The value of this variable is set through the console variable system, as seen in the FAutoConsoleVariableRef declaration.

It interacts with AsyncDt and UseAsyncInterpolation to determine whether async physics results should be used.

Developers should be aware that this variable is declared as CHAOS_API, meaning it’s exposed for use outside of the Chaos module.

Best practices for using ForceDisableAsyncPhysics include:

  1. Access it through the console variable system rather than directly modifying it in code.
  2. Use it in conjunction with other physics settings to achieve the desired simulation behavior.
  3. Be mindful of its global nature and potential impact on all physics solvers in the engine.

#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/PhysicsSolverBase.cpp:189

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:


	CHAOS_API int32 ForceDisableAsyncPhysics = 0;
	FAutoConsoleVariableRef CVarForceDisableAsyncPhysics(TEXT("p.ForceDisableAsyncPhysics"), ForceDisableAsyncPhysics, TEXT("Whether to force async physics off regardless of other settings"));

	auto LambdaMul = FConsoleVariableDelegate::CreateLambda([](IConsoleVariable* InVariable)
		{
			for (FPhysicsSolverBase* Solver : FChaosSolversModule::GetModule()->GetAllSolvers())
			{
				Solver->SetAsyncInterpolationMultiplier(InVariable->GetFloat());

#Associated Variable and Callsites

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

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

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

	FAutoConsoleVariableRef CVarUseAsyncInterpolation(TEXT("p.UseAsyncInterpolation"), UseAsyncInterpolation, TEXT("Whether to interpolate when async mode is enabled"));

	CHAOS_API int32 ForceDisableAsyncPhysics = 0;
	FAutoConsoleVariableRef CVarForceDisableAsyncPhysics(TEXT("p.ForceDisableAsyncPhysics"), ForceDisableAsyncPhysics, TEXT("Whether to force async physics off regardless of other settings"));

	auto LambdaMul = FConsoleVariableDelegate::CreateLambda([](IConsoleVariable* InVariable)
		{
			for (FPhysicsSolverBase* Solver : FChaosSolversModule::GetModule()->GetAllSolvers())
			{
				Solver->SetAsyncInterpolationMultiplier(InVariable->GetFloat());

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

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

	extern CHAOS_API int32 GSingleThreadedPhysics;
	extern CHAOS_API int32 UseAsyncInterpolation;
	extern CHAOS_API int32 ForceDisableAsyncPhysics;
	extern CHAOS_API FRealSingle AsyncInterpolationMultiplier;

	struct FSubStepInfo
	{
		FSubStepInfo()
			: PseudoFraction(1.0)

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

Scope (from outer to inner):

file
namespace    Chaos
class        class FPhysicsSolverBase : public FPhysicsSolverEvents
function     bool IsUsingAsyncResults

Source code excerpt:

		bool IsUsingAsyncResults() const
		{
			return !ForceDisableAsyncPhysics && AsyncDt >= 0;
		}

		bool IsUsingFixedDt() const
		{
			return IsUsingAsyncResults() && UseAsyncInterpolation;
		}