UE5 Chaos Physics 실전 활용
Chaos Physics는 UE5의 기본 물리 엔진으로 PhysX를 대체합니다. 대규모 구조체 파괴(Destruction), 천(Cloth), 헤어, 유체를 통합 처리하며 멀티스레드 기반으로 설계되었습니다.
1. 기본 물리 설정
섹션 제목: “1. 기본 물리 설정”// 리지드바디 물리 활성화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()); // 파편 효과, 사운드 등 처리 }};3. Field System — 외력 적용
섹션 제목: “3. Field System — 외력 적용”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);}4. Physics Constraint — 물리 제약
섹션 제목: “4. Physics Constraint — 물리 제약”// 두 컴포넌트를 힌지(경첩)로 연결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);5. 비동기 물리 조회
섹션 제목: “5. 비동기 물리 조회”// 비동기 라인 트레이스 (게임 스레드 블로킹 없음)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]);});6. Chaos 물리 디버그
섹션 제목: “6. Chaos 물리 디버그”; 콘솔 명령p.Chaos.DebugDraw.Enabled 1 ; 충돌 바운딩 박스 시각화p.Chaos.Solver.IterationCount 8 ; 물리 시뮬레이션 정확도p.Chaos.Solver.Positions 4 ; 위치 보정 반복 횟수p.ChaosSolverDebugDraw 1 ; 솔버 디버그 렌더링7. 성능 최적화
섹션 제목: “7. 성능 최적화”| 설정 | 권장값 | 설명 |
|---|---|---|
p.Chaos.Solver.IterationCount | 4~8 | 낮을수록 빠르지만 부정확 |
| Sleep 임계값 | 기본값 사용 | 정지한 물체를 슬립 처리 |
bNotifyBreaks | 필요한 경우만 | 브레이크 이벤트 오버헤드 |
| GeometryCollection LOD | 원거리 단순화 | 원거리 파괴체 폴리곤 감소 |
8. Physical Animation Component — 키네마틱 블렌딩
섹션 제목: “8. Physical Animation Component — 키네마틱 블렌딩”UPhysicalAnimationComponent는 물리 시뮬레이션과 애니메이션 사이를 스프링으로 블렌딩합니다. 상체는 애니메이션, 하체는 물리를 적용하는 부분 래그돌 구현에 사용합니다.
#include "PhysicsEngine/PhysicalAnimationComponent.h"
UCLASS()class AMyRagdollCharacter : public ACharacter{ GENERATED_BODY()
UPROPERTY(VisibleAnywhere) TObjectPtr<UPhysicalAnimationComponent> PhysicalAnim;
public: AMyRagdollCharacter() { PhysicalAnim = CreateDefaultSubobject<UPhysicalAnimationComponent>(TEXT("PhysAnim")); }
void EnablePartialRagdoll() { GetMesh()->SetSimulatePhysics(true); PhysicalAnim->SetSkeletalMeshComponent(GetMesh());
FPhysicalAnimationData AnimData; AnimData.bIsLocalSimulation = false; AnimData.OrientationStrength = 1000.f; // 회전 복원력 AnimData.AngularVelocityStrength = 100.f; AnimData.PositionStrength = 1000.f; // 위치 복원력 AnimData.VelocityStrength = 100.f;
// "pelvis" 본 이하 전체에 블렌딩 적용 (상체는 애니메이션 유지) PhysicalAnim->ApplyPhysicalAnimationSettingsBelow( TEXT("pelvis"), AnimData, /*bIncludeSelf=*/true); }};Chaos 솔버 콘솔 변수
섹션 제목: “Chaos 솔버 콘솔 변수”; 물리 솔버 품질 vs 성능 조정p.Chaos.Solver.IterationCount 8 ; 위치 반복 횟수 (기본 8, 낮출수록 빠름)p.Chaos.Solver.PushOut.Iterations 3 ; 충돌 분리 반복p.Chaos.Solver.Sleeping.Enabled 1 ; 정적 물체 Sleep 활성화 (성능 향상)p.Chaos.Collision.Enabled 1 ; 충돌 시뮬레이션 토글
; GeometryCollection 파괴 품질p.Chaos.Fracture.MinSleepVelocityFraction 0.05 ; 파편 Sleep 임계 속도 비율Chaos Physics는 Geometry Collection으로 현실감 있는 구조체 파괴를, Field System으로 영역 기반 물리 효과를, PhysicsConstraint로 복잡한 기계 구조를 구현합니다. 물리 시뮬레이션 비용은 IterationCount와 Sleep 설정으로 제어하고, 디버그 뷰를 활용해 충돌 형상이 예상대로 설정되었는지 확인하세요.