p.RagdollPhysics
p.RagdollPhysics
#Overview
name: p.RagdollPhysics
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
If 1, ragdoll physics will be used. Otherwise just root body is simulated
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.RagdollPhysics is to control the use of ragdoll physics in Unreal Engine’s skeletal mesh components. It is primarily used in the physics system, specifically for ragdoll simulations.
This setting variable is mainly utilized by the Engine module, particularly in the skeletal mesh component physics subsystem. The code references are found in the SkeletalMeshComponentPhysics.cpp file, which is part of the Engine’s runtime.
The value of this variable is set using a TAutoConsoleVariable, which means it can be changed at runtime through console commands. By default, it is set to 1, enabling ragdoll physics.
The associated variable CVarEnableRagdollPhysics directly interacts with p.RagdollPhysics. They share the same value and purpose.
Developers must be aware that when this variable is set to 0, only the root body of the skeletal mesh will be simulated, instead of the full ragdoll physics. This can significantly affect the behavior and performance of physics simulations for characters or other objects using skeletal meshes.
Best practices when using this variable include:
- Consider performance implications when enabling or disabling ragdoll physics.
- Test thoroughly with both settings (0 and 1) to ensure desired behavior in different scenarios.
- Use it in conjunction with other physics settings for fine-tuned control over ragdoll behavior.
Regarding the associated variable CVarEnableRagdollPhysics:
The purpose of CVarEnableRagdollPhysics is identical to p.RagdollPhysics. It’s a console variable that controls the use of ragdoll physics in the engine.
This variable is used within the Engine module, specifically in the skeletal mesh component physics system. It’s directly checked in the InstantiatePhysicsAssetBodies_Internal function of the USkeletalMeshComponent class.
The value of CVarEnableRagdollPhysics is set through the TAutoConsoleVariable declaration, which links it to the p.RagdollPhysics console command.
CVarEnableRagdollPhysics interacts directly with the p.RagdollPhysics setting, as they are essentially the same variable exposed through different interfaces.
Developers should be aware that this variable is checked during the instantiation of physics asset bodies. When set to 0, it prevents the creation of certain physics bodies in the global PhysX scenes.
Best practices for using CVarEnableRagdollPhysics include:
- Use GetValueOnGameThread() when accessing the value to ensure thread-safety.
- Consider the impact on physics simulation and performance when modifying this value.
- Coordinate its use with other physics-related settings for consistent behavior across the engine.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SkeletalMeshComponentPhysics.cpp:753
Scope: file
Source code excerpt:
}
TAutoConsoleVariable<int32> CVarEnableRagdollPhysics(TEXT("p.RagdollPhysics"), 1, TEXT("If 1, ragdoll physics will be used. Otherwise just root body is simulated"));
void USkeletalMeshComponent::InstantiatePhysicsAsset(const UPhysicsAsset& PhysAsset, const FVector& Scale3D, TArray<FBodyInstance*>& OutBodies, TArray<FConstraintInstance*>& OutConstraints, FPhysScene* PhysScene, USkeletalMeshComponent* OwningComponent, int32 UseRootBodyIndex, const FPhysicsAggregateHandle& UseAggregate) const
{
auto BoneTMCallable = [this](int32 BoneIndex)
{
return GetBoneTransform(BoneIndex);
#Associated Variable and Callsites
This variable is associated with another variable named CVarEnableRagdollPhysics
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SkeletalMeshComponentPhysics.cpp:753
Scope: file
Source code excerpt:
}
TAutoConsoleVariable<int32> CVarEnableRagdollPhysics(TEXT("p.RagdollPhysics"), 1, TEXT("If 1, ragdoll physics will be used. Otherwise just root body is simulated"));
void USkeletalMeshComponent::InstantiatePhysicsAsset(const UPhysicsAsset& PhysAsset, const FVector& Scale3D, TArray<FBodyInstance*>& OutBodies, TArray<FConstraintInstance*>& OutConstraints, FPhysScene* PhysScene, USkeletalMeshComponent* OwningComponent, int32 UseRootBodyIndex, const FPhysicsAggregateHandle& UseAggregate) const
{
auto BoneTMCallable = [this](int32 BoneIndex)
{
return GetBoneTransform(BoneIndex);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/SkeletalMeshComponentPhysics.cpp:873
Scope (from outer to inner):
file
function void USkeletalMeshComponent::InstantiatePhysicsAssetBodies_Internal
Source code excerpt:
{
BodyInst->DOFMode = EDOFMode::None;
if(PhysScene != nullptr && !CVarEnableRagdollPhysics.GetValueOnGameThread()) //We only limit creation of the global physx scenes and not assets related to immedate mode
{
continue;
}
}
// Create physics body instance.