콘텐츠로 이동

UE5 Chaos Physics 실전 활용

Chaos Physics는 UE5의 기본 물리 엔진으로 PhysX를 대체합니다. 대규모 구조체 파괴(Destruction), 천(Cloth), 헤어, 유체를 통합 처리하며 멀티스레드 기반으로 설계되었습니다.


// 리지드바디 물리 활성화
UStaticMeshComponent* Mesh = GetComponentByClass<UStaticMeshComponent>();
Mesh->SetSimulatePhysics(true);
Mesh->SetMassOverrideInKg(NAME_None, 50.0f);
Mesh->SetLinearDamping(0.1f);
Mesh->SetAngularDamping(0.05f);
// 충격 적용
Mesh->AddImpulse(FVector(0, 0, 5000.0f), NAME_None, true);
// 특정 위치에 힘 적용
Mesh->AddForceAtLocation(
FVector(1000, 0, 0),
GetActorLocation() + FVector(50, 0, 0));

2. Geometry Collection — 구조체 파괴

섹션 제목: “2. Geometry Collection — 구조체 파괴”
// GeometryCollectionComponent 설정 (C++)
UCLASS()
class ADestructibleWall : public AActor
{
GENERATED_BODY()
UPROPERTY(VisibleAnywhere)
UGeometryCollectionComponent* GeoCollection;
public:
ADestructibleWall()
{
GeoCollection = CreateDefaultSubobject<UGeometryCollectionComponent>(
TEXT("GeoCollection"));
RootComponent = GeoCollection;
// 자동 파괴 활성화
GeoCollection->SetSimulatePhysics(false);
GeoCollection->bNotifyBreaks = true;
}
// 파괴 이벤트 바인딩
virtual void BeginPlay() override
{
Super::BeginPlay();
GeoCollection->OnChaosBreakEvent.AddDynamic(
this, &ADestructibleWall::OnBreak);
}
UFUNCTION()
void OnBreak(const FChaosBreakEvent& BreakEvent)
{
UE_LOG(LogTemp, Log, TEXT("파괴 발생: %s"),
*BreakEvent.Component->GetName());
// 파편 효과, 사운드 등 처리
}
};

Field System으로 폭발, 중력 변화 등 영역 기반 물리력을 적용합니다.

#include "Field/FieldSystemComponent.h"
#include "Field/FieldSystemObjects.h"
void AExplosion::TriggerExplosion(FVector Center, float Radius, float Magnitude)
{
// 방사형 폴오프 필드
URadialFalloff* Falloff = NewObject<URadialFalloff>();
Falloff->Magnitude = Magnitude;
Falloff->MinRange = 0.0f;
Falloff->MaxRange = Radius;
Falloff->Default = 0.0f;
Falloff->Radius = Radius;
Falloff->Position = Center;
Falloff->Falloff = EFieldFalloffType::Field_Falloff_Linear;
// 선형 힘 필드
URadialVector* RadialVector = NewObject<URadialVector>();
RadialVector->Magnitude = Magnitude;
RadialVector->Position = Center;
// FieldSystem에 적용
FieldSystemComponent->ApplyPhysicsField(
true,
EFieldPhysicsType::Field_LinearForce,
nullptr,
RadialVector);
}

// 두 컴포넌트를 힌지(경첩)로 연결
UPhysicsConstraintComponent* Hinge =
CreateDefaultSubobject<UPhysicsConstraintComponent>(TEXT("Hinge"));
// 회전 제한 설정
Hinge->SetAngularSwing1Limit(EAngularConstraintMotion::ACM_Locked, 0.0f);
Hinge->SetAngularSwing2Limit(EAngularConstraintMotion::ACM_Locked, 0.0f);
Hinge->SetAngularTwistLimit(EAngularConstraintMotion::ACM_Free, 0.0f);
// 모터 설정 (자동 회전)
Hinge->SetAngularDriveMode(EAngularDriveMode::TwistAndSwing);
Hinge->SetAngularVelocityDriveTwistAndSwing(true, false);
Hinge->SetAngularVelocityTarget(FVector(0.0f, 0.0f, 90.0f)); // 90°/s
Hinge->SetConstrainedComponents(DoorMesh, NAME_None, FrameMesh, NAME_None);

// 비동기 라인 트레이스 (게임 스레드 블로킹 없음)
FCollisionQueryParams Params;
Params.AddIgnoredActor(this);
GetWorld()->AsyncLineTraceByChannel(
EAsyncTraceType::Single,
GetActorLocation(),
GetActorLocation() + GetActorForwardVector() * 1000.0f,
ECC_Visibility,
Params,
FCollisionResponseParams::DefaultResponseParam,
&TraceDelegate);
// 결과 처리 델리게이트
TraceDelegate.BindLambda([this](const FTraceHandle&, FTraceDatum& Data)
{
if (Data.OutHits.Num() > 0)
OnHit(Data.OutHits[0]);
});

; 콘솔 명령
p.Chaos.DebugDraw.Enabled 1 ; 충돌 바운딩 박스 시각화
p.Chaos.Solver.IterationCount 8 ; 물리 시뮬레이션 정확도
p.Chaos.Solver.Positions 4 ; 위치 보정 반복 횟수
p.ChaosSolverDebugDraw 1 ; 솔버 디버그 렌더링

설정권장값설명
p.Chaos.Solver.IterationCount4~8낮을수록 빠르지만 부정확
Sleep 임계값기본값 사용정지한 물체를 슬립 처리
bNotifyBreaks필요한 경우만브레이크 이벤트 오버헤드
GeometryCollection LOD원거리 단순화원거리 파괴체 폴리곤 감소

Chaos Physics는 Geometry Collection으로 현실감 있는 구조체 파괴를, Field System으로 영역 기반 물리 효과를, PhysicsConstraint로 복잡한 기계 구조를 구현합니다. 물리 시뮬레이션 비용은 IterationCount와 Sleep 설정으로 제어하고, 디버그 뷰를 활용해 충돌 형상이 예상대로 설정되었는지 확인하세요.