p.EnableDynamicPerBodyFilterHacks
p.EnableDynamicPerBodyFilterHacks
#Overview
name: p.EnableDynamicPerBodyFilterHacks
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Enables/Disables the use of a set of game focused hacks - allowing users to modify skel body collision dynamically (changes the behavior of per-body collision filtering).
It is referenced in 5
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.EnableDynamicPerBodyFilterHacks is to enable or disable a set of game-focused hacks that allow users to modify skeletal body collision dynamically. This setting variable is primarily used in the physics engine subsystem of Unreal Engine 5, specifically for collision filtering in body instances.
This setting variable is relied upon by the Engine module, particularly in the PhysicsEngine component. It’s used in the FBodyInstance class, which is responsible for managing physics properties of individual bodies in the engine.
The value of this variable is set through a console variable (CVar) named CVarEnableDynamicPerBodyFilterHacks. It’s initialized with a default value of 0 (disabled) and is marked as read-only, meaning it can’t be changed during runtime.
This variable interacts with two other variables: bHACK_DisableCollisionResponse and bHACK_DisableSkelComponentFilterOverriding. These are used when p.EnableDynamicPerBodyFilterHacks is enabled to modify collision behavior for skeletal bodies.
Developers must be aware that this is explicitly labeled as a HACK in the code comments. It’s intended as a temporary solution for games that need to dynamically modify collision per skeletal body. Using this variable may lead to unexpected behavior in collision filtering and should be used with caution.
Best practices when using this variable include:
- Only enable it if absolutely necessary for your game’s requirements.
- Be prepared to refactor your code when a more proper solution is implemented in future engine versions.
- Thoroughly test collision behavior when this hack is enabled to ensure it doesn’t introduce unintended side effects.
Regarding the associated variable CVarEnableDynamicPerBodyFilterHacks:
The purpose of CVarEnableDynamicPerBodyFilterHacks is to provide a runtime-accessible way to toggle the p.EnableDynamicPerBodyFilterHacks setting. It’s a console variable that directly controls the behavior enabled by p.EnableDynamicPerBodyFilterHacks.
This variable is used in the Engine module, specifically in the BodyInstance component of the PhysicsEngine.
The value of this variable is set when it’s declared, with a default value of 0 (disabled). It can be changed through console commands, but it’s marked as ECVF_ReadOnly, which means it should not be modified during gameplay.
CVarEnableDynamicPerBodyFilterHacks interacts directly with the bHACK_DisableCollisionResponse and bHACK_DisableSkelComponentFilterOverriding flags in the FBodyInstance class.
Developers should be aware that this is a console variable, meaning it can be changed at runtime through console commands. However, its read-only flag suggests that it’s not intended to be changed during normal gameplay.
Best practices for using this variable include:
- Use it for debugging or testing purposes only.
- Don’t rely on changing its value during normal gameplay.
- Be aware that enabling this variable may significantly change collision behavior in your game.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/BodyInstance.cpp:66
Scope: file
Source code excerpt:
// @HACK Guard to better encapsulate game related hacks introduced into UpdatePhysicsFilterData()
TAutoConsoleVariable<int32> CVarEnableDynamicPerBodyFilterHacks(
TEXT("p.EnableDynamicPerBodyFilterHacks"),
0,
TEXT("Enables/Disables the use of a set of game focused hacks - allowing users to modify skel body collision dynamically (changes the behavior of per-body collision filtering)."),
ECVF_ReadOnly
);
TAutoConsoleVariable<int32> CVarIgnoreAnalyticCollisionsOverride(
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/PhysicsEngine/BodyInstance.h:397
Scope: file
Source code excerpt:
/**
* @HACK:
* These are ONLY used when the 'p.EnableDynamicPerBodyFilterHacks' CVar is set (disabled by default).
* Some games need to dynamically modify collision per skeletal body. These provide game code a way to
* do that, until we're able to refactor how skeletal bodies work.
*/
uint8 bHACK_DisableCollisionResponse : 1;
/* By default, an owning skel mesh component will override the body's collision filter. This will disable that behavior. */
uint8 bHACK_DisableSkelComponentFilterOverriding : 1;
protected:
/** Whether this body instance has its own custom MaxDepenetrationVelocity*/
UPROPERTY(EditAnywhere, Category = Physics, meta=(InlineEditConditionToggle))
#Associated Variable and Callsites
This variable is associated with another variable named CVarEnableDynamicPerBodyFilterHacks
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/BodyInstance.cpp:65
Scope: file
Source code excerpt:
// @HACK Guard to better encapsulate game related hacks introduced into UpdatePhysicsFilterData()
TAutoConsoleVariable<int32> CVarEnableDynamicPerBodyFilterHacks(
TEXT("p.EnableDynamicPerBodyFilterHacks"),
0,
TEXT("Enables/Disables the use of a set of game focused hacks - allowing users to modify skel body collision dynamically (changes the behavior of per-body collision filtering)."),
ECVF_ReadOnly
);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/BodyInstance.cpp:4271
Scope (from outer to inner):
file
function void FBodyInstance::BuildBodyFilterData
Source code excerpt:
if(USkeletalMeshComponent* SkelMeshComp = Cast<USkeletalMeshComponent>(OwnerComponentInst))
{
if (CVarEnableDynamicPerBodyFilterHacks.GetValueOnGameThread() && bHACK_DisableCollisionResponse)
{
UseResponse.SetAllChannels(ECR_Ignore);
UseCollisionEnabled = ECollisionEnabled::PhysicsOnly;
}
else if(BodySetup->CollisionReponse == EBodyCollisionResponse::BodyCollision_Enabled)
{
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PhysicsEngine/BodyInstance.cpp:4286
Scope (from outer to inner):
file
function void FBodyInstance::BuildBodyFilterData
Source code excerpt:
}
const bool bDisableSkelComponentOverride = CVarEnableDynamicPerBodyFilterHacks.GetValueOnGameThread() && bHACK_DisableSkelComponentFilterOverriding;
if (bDisableSkelComponentOverride)
{
// if we are disabling the skeletal component override, we want the original body instance collision response
// this is to allow per body instance collision filtering instead of taking the data from the skeletal mesh
UseResponse = CollisionResponses.GetResponseContainer();
}