p.ConstraintLinearStiffnessScale

p.ConstraintLinearStiffnessScale

#Overview

name: p.ConstraintLinearStiffnessScale

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

The Unreal Engine subsystem that relies on this setting variable is the physics engine, specifically the constraint system. This can be seen from the file locations where the variable is referenced, such as “Engine/Source/Runtime/Engine/Private/PhysicsEngine/ConstraintInstance.cpp” and “Engine/Source/Runtime/Engine/Private/PhysicsEngine/ConstraintTypes.cpp”.

The value of this variable is set as a console variable with a default value of 1.0. It can be modified at runtime through the console or programmatically.

This variable interacts with several other constraint-related variables, such as CVarConstraintAngularStiffnessScale, CVarConstraintAngularDampingScale, and CVarConstraintLinearDampingScale. These variables work together to fine-tune the behavior of physical constraints in the simulation.

Developers must be aware that changing this variable will affect the stiffness of linear constraints in the physics simulation. A higher value will increase the stiffness, while a lower value will decrease it. This can have significant impacts on the behavior of constrained objects in the game world.

Best practices when using this variable include:

  1. Use it sparingly and with careful consideration of its effects on gameplay and performance.
  2. Test thoroughly after making changes to ensure desired physics behavior.
  3. Consider exposing it as a configurable option for advanced users or developers, but not for general players.

Regarding the associated variable CVarConstraintLinearStiffnessScale:

The purpose of CVarConstraintLinearStiffnessScale is to provide programmatic access to the p.ConstraintLinearStiffnessScale value within the C++ code of Unreal Engine.

This variable is used within the physics engine subsystem, particularly in constraint-related calculations and adjustments.

The value of CVarConstraintLinearStiffnessScale is set when the p.ConstraintLinearStiffnessScale console variable is initialized or modified.

It interacts with other constraint-related variables in a similar manner to p.ConstraintLinearStiffnessScale, as they share the same value.

Developers should be aware that this variable provides a way to access and use the constraint linear stiffness scale value in C++ code, allowing for dynamic adjustments to physics behavior.

Best practices for using CVarConstraintLinearStiffnessScale include:

  1. Use GetValueOnAnyThread() to safely access its value from any thread.
  2. Consider caching the value if it’s accessed frequently, to avoid potential performance impacts of repeated console variable lookups.
  3. Be cautious when modifying this variable, as it will directly affect the physics simulation’s behavior.

#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:28

Scope: file

Source code excerpt:


TAutoConsoleVariable<float> CVarConstraintLinearStiffnessScale(
	TEXT("p.ConstraintLinearStiffnessScale"),
	1.f,
	TEXT("The multiplier of constraint linear stiffness in simulation. Default: 1"),
	ECVF_ReadOnly);

TAutoConsoleVariable<float> CVarConstraintAngularDampingScale(
	TEXT("p.ConstraintAngularDampingScale"),

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_ReadOnly);

TAutoConsoleVariable<float> CVarConstraintLinearStiffnessScale(
	TEXT("p.ConstraintLinearStiffnessScale"),
	1.f,
	TEXT("The multiplier of constraint linear stiffness in simulation. Default: 1"),
	ECVF_ReadOnly);

TAutoConsoleVariable<float> CVarConstraintAngularDampingScale(

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

Scope (from outer to inner):

file
function     void FConstraintInstance::PostSerialize

Source code excerpt:

		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:7

Scope: file

Source code excerpt:


extern TAutoConsoleVariable<float> CVarConstraintLinearDampingScale;
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)
{