p.DefaultCollisionRestitution

p.DefaultCollisionRestitution

#Overview

name: p.DefaultCollisionRestitution

This variable is created as a Console Variable (cvar).

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.DefaultCollisionRestitution is to set the default collision restitution value when no materials are found in the physics simulation system of Unreal Engine 5. This setting variable is part of the physics simulation subsystem, specifically the collision handling component.

The Unreal Engine subsystem that relies on this setting variable is the Experimental Chaos physics engine, as evidenced by the file path “Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDCollisionConstraints.cpp”.

The value of this variable is set using an FAutoConsoleVariableRef, which allows it to be modified at runtime through console commands. The initial value is set to 0.

This variable interacts with other physics-related variables, such as DefaultCollisionFriction and CollisionRestitutionThresholdOverride. It is used in conjunction with these variables to define the behavior of collisions in the physics simulation.

Developers must be aware that this variable serves as a fallback value when no specific material properties are defined for colliding objects. It’s important to note that this is part of the experimental Chaos physics engine, so its behavior may change in future versions of Unreal Engine.

Best practices when using this variable include:

  1. Using it as a baseline for general collision behavior in your game.
  2. Overriding this value with specific material properties for more precise control over individual object interactions.
  3. Keeping in mind that a value of 0 means no bounce (inelastic collision), while higher values will result in more bounce.

Regarding the associated variable DefaultCollisionRestitution:

The purpose of DefaultCollisionRestitution is to store the actual value of the default collision restitution. It is directly linked to the console variable p.DefaultCollisionRestitution.

This variable is used within the Chaos physics engine, specifically in the FPBDCollisionConstraints::UpdateConstraintMaterialProperties function, where it’s assigned to MaterialRestitution when no specific material properties are found.

The value of DefaultCollisionRestitution is set through the console variable p.DefaultCollisionRestitution, allowing for runtime modification.

It interacts closely with other physics properties like DefaultCollisionFriction and is used alongside MaterialDynamicFriction and MaterialStaticFriction in setting up collision properties.

Developers should be aware that this variable directly affects the bounciness of collisions when no specific material properties are defined. It’s crucial for defining the default physical behavior of objects in the simulation.

Best practices for using DefaultCollisionRestitution include:

  1. Adjusting it to achieve the desired general collision behavior in your game.
  2. Using it as a starting point and then fine-tuning individual object behaviors with specific material properties.
  3. Considering the performance implications of very high restitution values, which may lead to prolonged collision resolution calculations.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDCollisionConstraints.cpp:64

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:


	FRealSingle DefaultCollisionRestitution = 0;
	FAutoConsoleVariableRef CVarDefaultCollisionRestitution(TEXT("p.DefaultCollisionRestitution"), DefaultCollisionRestitution, TEXT("Collision restitution default value if no materials are found."));

	FRealSingle CollisionRestitutionThresholdOverride = -1.0f;
	FAutoConsoleVariableRef CVarDefaultCollisionRestitutionThreshold(TEXT("p.CollisionRestitutionThreshold"), CollisionRestitutionThresholdOverride, TEXT("Collision restitution threshold override if >= 0 (units of acceleration)"));

	int32 CollisionCanAlwaysDisableContacts = 0;
	FAutoConsoleVariableRef CVarCollisionCanAlwaysDisableContacts(TEXT("p.CollisionCanAlwaysDisableContacts"), CollisionCanAlwaysDisableContacts, TEXT("Collision culling will always be able to permanently disable contacts"));

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDCollisionConstraints.cpp:63

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

	FAutoConsoleVariableRef CVarDefaultCollisionFriction(TEXT("p.DefaultCollisionFriction"), DefaultCollisionFriction, TEXT("Collision friction default value if no materials are found."));

	FRealSingle DefaultCollisionRestitution = 0;
	FAutoConsoleVariableRef CVarDefaultCollisionRestitution(TEXT("p.DefaultCollisionRestitution"), DefaultCollisionRestitution, TEXT("Collision restitution default value if no materials are found."));

	FRealSingle CollisionRestitutionThresholdOverride = -1.0f;
	FAutoConsoleVariableRef CVarDefaultCollisionRestitutionThreshold(TEXT("p.CollisionRestitutionThreshold"), CollisionRestitutionThresholdOverride, TEXT("Collision restitution threshold override if >= 0 (units of acceleration)"));

	int32 CollisionCanAlwaysDisableContacts = 0;
	FAutoConsoleVariableRef CVarCollisionCanAlwaysDisableContacts(TEXT("p.CollisionCanAlwaysDisableContacts"), CollisionCanAlwaysDisableContacts, TEXT("Collision culling will always be able to permanently disable contacts"));

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDCollisionConstraints.cpp:500

Scope (from outer to inner):

file
namespace    Chaos
function     void FPBDCollisionConstraints::UpdateConstraintMaterialProperties

Source code excerpt:

			MaterialDynamicFriction = DefaultCollisionFriction;
			MaterialStaticFriction = DefaultCollisionFriction;
			MaterialRestitution = DefaultCollisionRestitution;
		}

		MaterialRestitutionThreshold = RestitutionThreshold;

		// Overrides for testing
		if (CollisionFrictionOverride >= 0)