UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
BodyInstance.cpp File Reference
#include "PhysicsEngine/BodyInstance.h"
#include "BodySetupEnums.h"
#include "Components/StaticMeshComponent.h"
#include "Chaos/CollisionConvexMesh.h"
#include "Engine/Engine.h"
#include "Components/SkeletalMeshComponent.h"
#include "Components/ShapeComponent.h"
#include "GameFramework/Actor.h"
#include "Engine/CollisionProfile.h"
#include "Engine/OverlapResult.h"
#include "Engine/World.h"
#include "PrimitiveDrawingUtils.h"
#include "Collision.h"
#include "Materials/MaterialInterface.h"
#include "Physics/PhysicsFiltering.h"
#include "Physics/Experimental/PhysScene_Chaos.h"
#include "PhysicsEngine/ConstraintInstance.h"
#include "Physics/PhysicsInterfaceTypes.h"
#include "PhysicsEngine/ConvexElem.h"
#include "PhysicsEngine/BoxElem.h"
#include "PhysicsEngine/LevelSetElem.h"
#include "PhysicsEngine/SphereElem.h"
#include "PhysicsEngine/SphylElem.h"
#include "PhysicsEngine/BodySetup.h"
#include "PhysicsEngine/BodyUtils.h"
#include "PhysicsEngine/PhysicsBodyInstanceOwnerInterface.h"
#include "Logging/MessageLog.h"
#include "Chaos/Capsule.h"
#include "Chaos/Convex.h"
#include "Chaos/TriangleMeshImplicitObject.h"
#include "Chaos/AsyncInitBodyHelper.h"
#include "Physics/Experimental/ChaosInterfaceUtils.h"
#include "PhysicsEngine/TaperedCapsuleElem.h"
#include "PhysicsProxy/SingleParticlePhysicsProxy.h"
#include "Components/BrushComponent.h"
#include "PhysicalMaterials/PhysicalMaterial.h"
#include "PhysicsEngine/PhysicsSettings.h"
#include "Chaos/ChaosEngineInterface.h"
#include "Physics/Experimental/ChaosScopedSceneLock.h"

Namespaces

namespace  Chaos
 
namespace  Chaos::Private
 
namespace  EScaleMode
 

Macros

#define LOCTEXT_NAMESPACE   "BodyInstance"
 

Typedefs

using BodyInstanceSingleElementArrayInlineAllocator = TInlineAllocator< 1 >
 
using FInitSingleBodyHelperStatic = FInitBodiesHelper< true, BodyInstanceSingleElementArrayInlineAllocator >
 
using FInitSingleBodyHelperDynamic = FInitBodiesHelper< false, BodyInstanceSingleElementArrayInlineAllocator >
 

Enumerations

enum  EScaleMode::Type { EScaleMode::Free , EScaleMode::LockedXY , EScaleMode::LockedXYZ }
 

Functions

 DECLARE_CYCLE_STAT (TEXT("Init Body"), STAT_InitBody, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT (TEXT("Init Body Debug"), STAT_InitBodyDebug, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT (TEXT("Init Body Scene Interaction"), STAT_InitBodySceneInteraction, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT (TEXT("Init Body Aggregate"), STAT_InitBodyAggregate, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT (TEXT("Init Body Add"), STAT_InitBodyAdd, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT (TEXT("Init Body Post Add to Scene"), STAT_InitBodyPostAdd, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT (TEXT("Term Body"), STAT_TermBody, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT (TEXT("Update Materials"), STAT_UpdatePhysMats, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT (TEXT("Update Materials Scene Interaction"), STAT_UpdatePhysMatsSceneInteraction, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT_WITH_FLAGS (TEXT("Filter Update"), STAT_UpdatePhysFilter, STATGROUP_Physics, EStatFlags::Verbose)
 
 DECLARE_CYCLE_STAT (TEXT("Filter Update (PhysX Code)"), STAT_UpdatePhysFilterPhysX, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT (TEXT("Init Bodies"), STAT_InitBodies, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT (TEXT("Bulk Body Scene Add"), STAT_BulkSceneAdd, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT (TEXT("Static Init Bodies"), STAT_StaticInitBodies, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT (TEXT("UpdateBodyScale"), STAT_BodyInstanceUpdateBodyScale, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT (TEXT("CreatePhysicsShapesAndActors"), STAT_CreatePhysicsShapesAndActors, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT (TEXT("CreatePhysicsShapes"), STAT_CreatePhysicsShapes, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT (TEXT("CreatePhysicsActor"), STAT_CreatePhysicsActor, STATGROUP_Physics)
 
 DECLARE_CYCLE_STAT_WITH_FLAGS (TEXT("BodyInstance SetCollisionProfileName"), STAT_BodyInst_SetCollisionProfileName, STATGROUP_Physics, EStatFlags::Verbose)
 
 DECLARE_CYCLE_STAT (TEXT("Phys SetBodyTransform"), STAT_SetBodyTransform, STATGROUP_Physics)
 
bool IsRigidBodyKinematic_AssumesLocked (const FPhysicsActorHandle &InActorRef)
 
int32 FillInlineShapeArray_AssumesLocked (PhysicsInterfaceTypes::FInlineShapeArray &Array, const FPhysicsActorHandle &Actor)
 
FArchiveoperator<< (FArchive &Ar, FBodyInstance &BodyInst)
 
FBodyInstanceFindParentBodyInstance (FName BodyName, USkeletalMeshComponent *SkelMeshComp)
 
template<typename InAllocatorType >
const FString & GetBodyInstanceDebugName (TInitBodiesHelperBase< InAllocatorType > &InitHelper)
 
bool ValidateTransformScale (const FTransform &Transform, const FString &DebugName)
 
bool ValidateTransformMirror (const FTransform &Transform, const FString &DebugName, bool bGenerateMirroredCollision, bool bGenerateNonMirroredCollision)
 
bool ValidateTransformNaN (const FTransform &Transform, const FString &DebugName, const FName &BoneName)
 
FVector GetInitialLinearVelocity (const AActor *OwningActor, bool &bComponentAwake)
 
float AdjustForSmallThreshold (float NewVal, float OldVal)
 
void ComputeScalingVectors (EScaleMode::Type ScaleMode, const FVector &InScale3D, FVector &OutScale3D, FVector &OutScale3DAbs)
 
EScaleMode::Type ComputeScaleMode (const TArray< FPhysicsShapeHandle > &Shapes)
 
FTransform GetUnrealWorldTransformImp_AssumesLocked (const FBodyInstance *BodyInstance, bool bWithProjection, bool bGlobalPose)
 
int32 GetNumSimShapes_AssumesLocked (const FPhysicsActorHandle &ActorRef)
 
FTransform RootSpaceToWeldedSpace (const FBodyInstance *BI, const FTransform &RootTM)
 

Variables

TAutoConsoleVariable< int32CVarEnableDynamicPerBodyFilterHacks (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< int32CVarIgnoreAnalyticCollisionsOverride (TEXT("p.IgnoreAnalyticCollisionsOverride"), 0, TEXT("Overrides the default for ignroing analytic collsions."), ECVF_ReadOnly)
 
bool bPreventInvalidBodyInstanceTransforms = true
 
FAutoConsoleVariableRef CVarbPreventInvalidBodyInstanceTransforms (TEXT("p.PreventInvalidBodyInstanceTransforms"), bPreventInvalidBodyInstanceTransforms, TEXT("If true, an attempt to create a BodyInstance with an invalid transform will fail with a warning"))
 
bool bEnableOverrideSolverDeltaTime = true
 
FAutoConsoleVariableRef CVarbEnableOverrideSolverDeltaTime (TEXT("p.EnableOverrideSolverDeltaTime"), bEnableOverrideSolverDeltaTime, TEXT("If true, setting for override solver delta time can be used. False will disable this feature."))
 
bool bSkipShapeCreationForEmptyBodySetup = false
 
FAutoConsoleVariableRef CVarSkipShapeCreationForEmptyBodySetup (TEXT("p.SkipShapeCreationForEmptyBodySetup"), bSkipShapeCreationForEmptyBodySetup, TEXT("If true, CreateShapesAndActors will not try to create actors and shapes for all instances if the body setup doesn't have any geometry."))
 
float SensitiveSleepThresholdMultiplier = 1.0f/20.0f
 
FAutoConsoleVariableRef CVarSensitiveSleepThresholdMultiplier (TEXT("p.SensitiveSleepThresholdMultiplier"), SensitiveSleepThresholdMultiplier, TEXT("The sleep threshold multiplier to use for bodies using the Sensitive sleep family."))
 
bool bClearPerShapeOverridesOnTerminate = true
 
FAutoConsoleVariableRef CVarClearPerShapeOverridesOnTerminate (TEXT("p.ClearPerShapeOverridesOnTerminate"), bClearPerShapeOverridesOnTerminate, TEXT("Whether shape overrides are cleared in between recreations of a body instance"))
 
TAutoConsoleVariable< int32CDisableQueryOnlyActors (TEXT("p.DisableQueryOnlyActors"), 0, TEXT("If QueryOnly is used, actors are marked as simulation disabled. This is NOT compatible with origin shifting at the moment."))
 
int32 EnsureUnweldModifiesGTOnly = 0
 
FAutoConsoleVariableRef CVarEnsureUnweldModifiesGTOnly (TEXT("p.EnsureUnweldModifiesGTOnly"), EnsureUnweldModifiesGTOnly, TEXT("Ensure if unweld modifies geometry shared with physics thread"))
 
int32 SimCollisionEnabled = 1
 
FAutoConsoleVariableRef CVarSimCollisionEnabled (TEXT("p.SimCollisionEnabled"), SimCollisionEnabled, TEXT("If 0 no sim collision will be used"))
 

Macro Definition Documentation

◆ LOCTEXT_NAMESPACE

#define LOCTEXT_NAMESPACE   "BodyInstance"

Typedef Documentation

◆ BodyInstanceSingleElementArrayInlineAllocator

◆ FInitSingleBodyHelperDynamic

◆ FInitSingleBodyHelperStatic

Function Documentation

◆ AdjustForSmallThreshold()

float AdjustForSmallThreshold ( float  NewVal,
float  OldVal 
)

◆ ComputeScaleMode()

EScaleMode::Type ComputeScaleMode ( const TArray< FPhysicsShapeHandle > &  Shapes)

◆ ComputeScalingVectors()

void ComputeScalingVectors ( EScaleMode::Type  ScaleMode,
const FVector InScale3D,
FVector OutScale3D,
FVector OutScale3DAbs 
)

◆ DECLARE_CYCLE_STAT() [1/18]

DECLARE_CYCLE_STAT ( TEXT("Bulk Body Scene Add" ,
STAT_BulkSceneAdd  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [2/18]

DECLARE_CYCLE_STAT ( TEXT("CreatePhysicsActor")  ,
STAT_CreatePhysicsActor  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [3/18]

DECLARE_CYCLE_STAT ( TEXT("CreatePhysicsShapes")  ,
STAT_CreatePhysicsShapes  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [4/18]

DECLARE_CYCLE_STAT ( TEXT("CreatePhysicsShapesAndActors")  ,
STAT_CreatePhysicsShapesAndActors  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [5/18]

DECLARE_CYCLE_STAT ( TEXT("Filter Update (PhysX Code)")  ,
STAT_UpdatePhysFilterPhysX  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [6/18]

DECLARE_CYCLE_STAT ( TEXT("Init Bodies" ,
STAT_InitBodies  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [7/18]

DECLARE_CYCLE_STAT ( TEXT("Init Body Add" ,
STAT_InitBodyAdd  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [8/18]

DECLARE_CYCLE_STAT ( TEXT("Init Body Aggregate" ,
STAT_InitBodyAggregate  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [9/18]

DECLARE_CYCLE_STAT ( TEXT("Init Body Debug" ,
STAT_InitBodyDebug  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [10/18]

DECLARE_CYCLE_STAT ( TEXT("Init Body Post Add to Scene" ,
STAT_InitBodyPostAdd  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [11/18]

DECLARE_CYCLE_STAT ( TEXT("Init Body Scene Interaction" ,
STAT_InitBodySceneInteraction  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [12/18]

DECLARE_CYCLE_STAT ( TEXT("Init Body" ,
STAT_InitBody  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [13/18]

DECLARE_CYCLE_STAT ( TEXT("Phys SetBodyTransform" ,
STAT_SetBodyTransform  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [14/18]

DECLARE_CYCLE_STAT ( TEXT("Static Init Bodies" ,
STAT_StaticInitBodies  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [15/18]

DECLARE_CYCLE_STAT ( TEXT("Term Body" ,
STAT_TermBody  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [16/18]

◆ DECLARE_CYCLE_STAT() [17/18]

DECLARE_CYCLE_STAT ( TEXT("Update Materials" ,
STAT_UpdatePhysMats  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT() [18/18]

DECLARE_CYCLE_STAT ( TEXT("UpdateBodyScale")  ,
STAT_BodyInstanceUpdateBodyScale  ,
STATGROUP_Physics   
)

◆ DECLARE_CYCLE_STAT_WITH_FLAGS() [1/2]

DECLARE_CYCLE_STAT_WITH_FLAGS ( TEXT("BodyInstance SetCollisionProfileName" ,
STAT_BodyInst_SetCollisionProfileName  ,
STATGROUP_Physics  ,
EStatFlags::Verbose   
)

◆ DECLARE_CYCLE_STAT_WITH_FLAGS() [2/2]

DECLARE_CYCLE_STAT_WITH_FLAGS ( TEXT("Filter Update" ,
STAT_UpdatePhysFilter  ,
STATGROUP_Physics  ,
EStatFlags::Verbose   
)

◆ FillInlineShapeArray_AssumesLocked()

int32 FillInlineShapeArray_AssumesLocked ( PhysicsInterfaceTypes::FInlineShapeArray Array,
const FPhysicsActorHandle Actor 
)

◆ FindParentBodyInstance()

FBodyInstance * FindParentBodyInstance ( FName  BodyName,
USkeletalMeshComponent *  SkelMeshComp 
)

Util for finding the parent bodyinstance of a specified body, using skeleton hierarchy

◆ GetBodyInstanceDebugName()

const FString & GetBodyInstanceDebugName ( TInitBodiesHelperBase< InAllocatorType > &  InitHelper)

◆ GetInitialLinearVelocity()

FVector GetInitialLinearVelocity ( const AActor OwningActor,
bool bComponentAwake 
)

◆ GetNumSimShapes_AssumesLocked()

int32 GetNumSimShapes_AssumesLocked ( const FPhysicsActorHandle ActorRef)

Util for finding the number of 'collision sim' shapes on this Actor

◆ GetUnrealWorldTransformImp_AssumesLocked()

FTransform GetUnrealWorldTransformImp_AssumesLocked ( const FBodyInstance BodyInstance,
bool  bWithProjection,
bool  bGlobalPose 
)

◆ IsRigidBodyKinematic_AssumesLocked()

bool IsRigidBodyKinematic_AssumesLocked ( const FPhysicsActorHandle InActorRef)

◆ operator<<()

FArchive & operator<< ( FArchive Ar,
FBodyInstance BodyInst 
)

◆ RootSpaceToWeldedSpace()

FTransform RootSpaceToWeldedSpace ( const FBodyInstance BI,
const FTransform RootTM 
)

◆ ValidateTransformMirror()

bool ValidateTransformMirror ( const FTransform Transform,
const FString &  DebugName,
bool  bGenerateMirroredCollision,
bool  bGenerateNonMirroredCollision 
)

◆ ValidateTransformNaN()

bool ValidateTransformNaN ( const FTransform Transform,
const FString &  DebugName,
const FName BoneName 
)

◆ ValidateTransformScale()

bool ValidateTransformScale ( const FTransform Transform,
const FString &  DebugName 
)

Variable Documentation

◆ bClearPerShapeOverridesOnTerminate

bool bClearPerShapeOverridesOnTerminate = true

◆ bEnableOverrideSolverDeltaTime

bool bEnableOverrideSolverDeltaTime = true

◆ bPreventInvalidBodyInstanceTransforms

bool bPreventInvalidBodyInstanceTransforms = true

◆ bSkipShapeCreationForEmptyBodySetup

bool bSkipShapeCreationForEmptyBodySetup = false

◆ CDisableQueryOnlyActors

TAutoConsoleVariable< int32 > CDisableQueryOnlyActors(TEXT("p.DisableQueryOnlyActors"), 0, TEXT("If QueryOnly is used, actors are marked as simulation disabled. This is NOT compatible with origin shifting at the moment.")) ( TEXT("p.DisableQueryOnlyActors")  ,
,
TEXT("If QueryOnly is used, actors are marked as simulation disabled. This is NOT compatible with origin shifting at the moment."  
)

◆ CVarbEnableOverrideSolverDeltaTime

FAutoConsoleVariableRef CVarbEnableOverrideSolverDeltaTime(TEXT("p.EnableOverrideSolverDeltaTime"), bEnableOverrideSolverDeltaTime, TEXT("If true, setting for override solver delta time can be used. False will disable this feature.")) ( TEXT("p.EnableOverrideSolverDeltaTime")  ,
bEnableOverrideSolverDeltaTime  ,
TEXT("If true, setting for override solver delta time can be used. False will disable this feature."  
)

◆ CVarbPreventInvalidBodyInstanceTransforms

FAutoConsoleVariableRef CVarbPreventInvalidBodyInstanceTransforms(TEXT("p.PreventInvalidBodyInstanceTransforms"), bPreventInvalidBodyInstanceTransforms, TEXT("If true, an attempt to create a BodyInstance with an invalid transform will fail with a warning")) ( TEXT("p.PreventInvalidBodyInstanceTransforms")  ,
bPreventInvalidBodyInstanceTransforms  ,
TEXT("If true, an attempt to create a BodyInstance with an invalid transform will fail with a warning"  
)

◆ CVarClearPerShapeOverridesOnTerminate

FAutoConsoleVariableRef CVarClearPerShapeOverridesOnTerminate(TEXT("p.ClearPerShapeOverridesOnTerminate"), bClearPerShapeOverridesOnTerminate, TEXT("Whether shape overrides are cleared in between recreations of a body instance")) ( TEXT("p.ClearPerShapeOverridesOnTerminate")  ,
bClearPerShapeOverridesOnTerminate  ,
TEXT("Whether shape overrides are cleared in between recreations of a body instance"  
)

◆ CVarEnableDynamicPerBodyFilterHacks

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) ( TEXT("p.EnableDynamicPerBodyFilterHacks")  ,
,
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   
)

◆ CVarEnsureUnweldModifiesGTOnly

FAutoConsoleVariableRef CVarEnsureUnweldModifiesGTOnly(TEXT("p.EnsureUnweldModifiesGTOnly"), EnsureUnweldModifiesGTOnly, TEXT("Ensure if unweld modifies geometry shared with physics thread")) ( TEXT("p.EnsureUnweldModifiesGTOnly")  ,
EnsureUnweldModifiesGTOnly  ,
TEXT("Ensure if unweld modifies geometry shared with physics thread"  
)

◆ CVarIgnoreAnalyticCollisionsOverride

TAutoConsoleVariable< int32 > CVarIgnoreAnalyticCollisionsOverride(TEXT("p.IgnoreAnalyticCollisionsOverride"), 0, TEXT("Overrides the default for ignroing analytic collsions."), ECVF_ReadOnly) ( TEXT("p.IgnoreAnalyticCollisionsOverride")  ,
,
TEXT("Overrides the default for ignroing analytic collsions." ,
ECVF_ReadOnly   
)

◆ CVarSensitiveSleepThresholdMultiplier

FAutoConsoleVariableRef CVarSensitiveSleepThresholdMultiplier(TEXT("p.SensitiveSleepThresholdMultiplier"), SensitiveSleepThresholdMultiplier, TEXT("The sleep threshold multiplier to use for bodies using the Sensitive sleep family.")) ( TEXT("p.SensitiveSleepThresholdMultiplier")  ,
SensitiveSleepThresholdMultiplier  ,
TEXT("The sleep threshold multiplier to use for bodies using the Sensitive sleep family."  
)

◆ CVarSimCollisionEnabled

FAutoConsoleVariableRef CVarSimCollisionEnabled(TEXT("p.SimCollisionEnabled"), SimCollisionEnabled, TEXT("If 0 no sim collision will be used")) ( TEXT("p.SimCollisionEnabled")  ,
SimCollisionEnabled  ,
TEXT("If 0 no sim collision will be used"  
)

◆ CVarSkipShapeCreationForEmptyBodySetup

FAutoConsoleVariableRef CVarSkipShapeCreationForEmptyBodySetup(TEXT("p.SkipShapeCreationForEmptyBodySetup"), bSkipShapeCreationForEmptyBodySetup, TEXT("If true, CreateShapesAndActors will not try to create actors and shapes for all instances if the body setup doesn't have any geometry.")) ( TEXT("p.SkipShapeCreationForEmptyBodySetup")  ,
bSkipShapeCreationForEmptyBodySetup  ,
TEXT("If true, CreateShapesAndActors will not try to create actors and shapes for all instances if the body setup doesn't have any geometry."  
)

◆ EnsureUnweldModifiesGTOnly

int32 EnsureUnweldModifiesGTOnly = 0

◆ SensitiveSleepThresholdMultiplier

float SensitiveSleepThresholdMultiplier = 1.0f/20.0f

◆ SimCollisionEnabled

int32 SimCollisionEnabled = 1