p.ConstraintAngularStiffnessScale

p.ConstraintAngularStiffnessScale

#Overview

name: p.ConstraintAngularStiffnessScale

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.ConstraintAngularStiffnessScale is to provide a multiplier for the angular stiffness of constraints in physics simulations within Unreal Engine 5. This setting variable is primarily used in the physics engine subsystem, specifically for adjusting the behavior of physical constraints.

The Unreal Engine subsystem that relies on this setting variable is the physics engine, particularly the constraint system used in skeletal mesh animations and other physics-based simulations.

The value of this variable is set as a console variable with a default value of 100000.0. It is defined in the ConstraintInstance.cpp file within the Engine/Source/Runtime/Engine/Private/PhysicsEngine/ directory.

This variable interacts closely with its associated variable CVarConstraintAngularStiffnessScale, which is an instance of TAutoConsoleVariable. They share the same value and are used interchangeably in the code.

Developers must be aware that this variable affects the stiffness of angular constraints in physics simulations. Modifying this value will change how rigid or flexible angular constraints behave in the game. It’s also important to note that this variable is marked as ECVF_ReadOnly, meaning it should not be changed during runtime.

Best practices when using this variable include:

  1. Carefully consider the impact on physics simulations before modifying the default value.
  2. Use it in conjunction with other physics-related variables to achieve the desired constraint behavior.
  3. Test thoroughly after any modifications to ensure the physics simulations behave as expected across different scenarios.

Regarding the associated variable CVarConstraintAngularStiffnessScale:

The purpose of CVarConstraintAngularStiffnessScale is to provide a programmatic interface to the p.ConstraintAngularStiffnessScale console variable. It allows C++ code to read and potentially modify the constraint angular stiffness scale.

This variable is used in the same physics engine subsystem as p.ConstraintAngularStiffnessScale, specifically in constraint-related calculations and adjustments.

The value of CVarConstraintAngularStiffnessScale is set when the TAutoConsoleVariable is initialized, which occurs in the ConstraintInstance.cpp file.

CVarConstraintAngularStiffnessScale interacts with several other physics-related variables, such as CVarConstraintAngularDampingScale and CVarConstraintLinearStiffnessScale, as seen in the PostSerialize function.

Developers should be aware that this variable is used in critical physics calculations, particularly when adjusting constraint properties during serialization and deserialization processes. It’s also used to scale various constraint stiffness values.

Best practices for using CVarConstraintAngularStiffnessScale include:

  1. Use GetValueOnAnyThread() when accessing its value to ensure thread-safe operations.
  2. Consider the interdependencies with other physics variables when making adjustments.
  3. Be cautious when modifying its value, as it can significantly impact the behavior of physics constraints in the engine.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/ConstraintInstance.cpp:40

Scope: file

Source code excerpt:


TAutoConsoleVariable<float> CVarConstraintAngularStiffnessScale(
	TEXT("p.ConstraintAngularStiffnessScale"),
	100000.f,
	TEXT("The multiplier of constraint angular stiffness in simulation. Default: 100000"),
	ECVF_ReadOnly);

bool bEnableSkeletalMeshConstraints = true;
FAutoConsoleVariableRef CVarEnableSkeletalMeshConstraints(TEXT("p.EnableSkeletalMeshConstraints"), bEnableSkeletalMeshConstraints, TEXT("Enable skeletal mesh constraints defined within the Physics Asset Editor"));

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/ConstraintInstance.cpp:39

Scope: file

Source code excerpt:

	ECVF_ReadOnly);

TAutoConsoleVariable<float> CVarConstraintAngularStiffnessScale(
	TEXT("p.ConstraintAngularStiffnessScale"),
	100000.f,
	TEXT("The multiplier of constraint angular stiffness in simulation. Default: 100000"),
	ECVF_ReadOnly);

bool bEnableSkeletalMeshConstraints = true;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/ConstraintInstance.cpp:1163

Scope (from outer to inner):

file
function     void FConstraintInstance::PostSerialize

Source code excerpt:

	if (Ar.IsLoading() && Ar.UEVer() < VER_UE4_FIXUP_STIFFNESS_AND_DAMPING_SCALE)
	{
		LinearLimitStiffness_DEPRECATED		/= CVarConstraintAngularStiffnessScale.GetValueOnAnyThread();
		SwingLimitStiffness_DEPRECATED		/= CVarConstraintAngularStiffnessScale.GetValueOnAnyThread();
		TwistLimitStiffness_DEPRECATED		/= CVarConstraintAngularStiffnessScale.GetValueOnAnyThread();
		LinearLimitDamping_DEPRECATED		/=  CVarConstraintAngularDampingScale.GetValueOnAnyThread();
		SwingLimitDamping_DEPRECATED		/=  CVarConstraintAngularDampingScale.GetValueOnAnyThread();
		TwistLimitDamping_DEPRECATED		/=  CVarConstraintAngularDampingScale.GetValueOnAnyThread();
	}

	if (Ar.IsLoading() && Ar.UEVer() < VER_UE4_FIXUP_MOTOR_UNITS)

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/ConstraintInstance.cpp:1282

Scope (from outer to inner):

file
function     void FConstraintInstance::PostSerialize

Source code excerpt:


		//Now handle the new linear spring stiffness and damping coefficient
		if(CVarConstraintAngularStiffnessScale.GetValueOnAnyThread() > 0.f)
		{
			ProfileInstance.LinearLimit.Stiffness *= CVarConstraintAngularStiffnessScale.GetValueOnAnyThread() / CVarConstraintLinearStiffnessScale.GetValueOnAnyThread();
		}

		if (CVarConstraintAngularDampingScale.GetValueOnAnyThread() > 0.f)
		{
			ProfileInstance.LinearLimit.Damping *= CVarConstraintAngularDampingScale.GetValueOnAnyThread() / CVarConstraintLinearDampingScale.GetValueOnAnyThread();
		}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/ConstraintTypes.cpp:9

Scope: file

Source code excerpt:

extern TAutoConsoleVariable<float> CVarConstraintLinearStiffnessScale;
extern TAutoConsoleVariable<float> CVarConstraintAngularDampingScale;
extern TAutoConsoleVariable<float> CVarConstraintAngularStiffnessScale;

/** Util for setting linear movement for an axis */
void SetLinearMovement_AssumesLocked(const FPhysicsConstraintHandle& InConstraintRef, PhysicsInterfaceTypes::ELimitAxis InAxis, ELinearConstraintMotion Motion, bool bLockLimitSize, bool bSkipSoftLimit)
{
	if(Motion == LCM_Locked || (Motion == LCM_Limited && bLockLimitSize))
	{