🎮Unreal4/Blueprint

[UE4] 무기 충돌 구조 (USpaceComponent)

공대 컴린이 2023. 1. 30. 23:48
728x90

🚩 무기 충돌 구조 짜기 (USpaceComponent)

UCapsulComponent의 상속구조

  • UPrimitiveComponent
    Primitive Rendering 데이터나 Vertex Index 데이터같은 일종의 기하학을 포함하거나 생성하는 Scene 컴포넌트
  • UShapeComponent
    단순한 기하학적 모양으로 표현되는 Primitive 컴포넌트이며 충돌체 3개(box, Sphere, Capsule)의 부모이다!

해당 내용이 언급된 이유는 게임을 제작할 때 여러 종류의 Weapon을 제작하는데, 이때 캡슐 충돌체를 쓸지 박스 충돌체를 쓸지 미리 알지 못한다. 이런경우 부모 클래스인 Weapon이 자식 클래스들(종류 별 무기들)의 충돌 관리를 구현할 때 어떤 충돌인지 모르니 Shape Component로 모두 처리할 수 있다. 또한 몇개의 충돌체가 존재하는지 미리 알 수 없으므로 Components 로 선언해서 모든 충돌체를 관리하면 된다!

 

Weapon 부모 클래스 (Weapon Combo)

위 설명대로 구현한 Weapon의 부모 클래스이다. (실제로는 Weapon - WeaponCombo - ComboSword 처럼 상속이 여러단계지만 지금은 설명하기 쉽게 부모라고 칭함)

Get Components By Class 함수를 통해 Shape Component로 반환되는 모든 충돌체를 Collisions 배열(유형: Shape Component)에 저장한 뒤, 첫 초기화 단계이기 때문에 충돌체를 모두 Off 처리 해주었다. 이후에 존재하는 모든 충돌체의 충돌 처리를 위한 On Component Begin Overlap 이벤트에 바인딩하였다. 

해당 이벤트는 디스패처와 같은 역할을 수행할 수 있어 이벤트 바인딩이 가능하다.


참조

https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/Components/UShapeComponent/

 

UShapeComponent

ShapeComponent is a PrimitiveComponent that is represented by a simple geometrical shape (sphere, capsule, box, etc).

docs.unrealengine.com

 

728x90