[Unreal]#6_Gun Actor Setting

2022. 8. 11. 01:10· 게임개발/Unreal C++
목차
  1. [Unreal]#6_Gun Actor Setting

[Unreal]#6_Gun Actor Setting

Unreal 개발 중 "Gun Actor"에 대해 알아보겠습니다.

"Simple Shooter Game"의 Character Class 개발 과정 중 일부입니다.

 

 


 

Gun Actor

 

* 상속 구조
1. Capsule Component : Collision
2. Mesh Component : Skeleton Mesh + Animation
3. Mesh Component : Gun Actor
4. Particle System : Particle Effect of Gun

우리가 앞으로 구현할 "Actor", 총은 "Character"의 Mesh Component의 하위 Component가 됩니다.

 

1. C++ Actor Class 생성

1. 새로운 C++ "Actor" 클래스 생성 

2. 클래스의 이름은 "Gun"으로 합니다.

 

* 주의 : 구현할 Gun Class는 "Pawn" 클래스처럼 소유하거나, "Character" 클래스처럼 이동을 하지 않습니다!

 

2. 파생 Blueprint Class 생성

 

3. C++ 클래스에서 Component를 데이터 멤버로 선언

// Gun.h 내부

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "TestGun.generated.h"

UCLASS()
class SIMPLESHOOTER_API ATestGun : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ATestGun();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

// Gun 클래스에 추가할 컴포넌트들을 데이터 멤버로 선언합니다.
private:
	// 1. Root Component가 될 SceneComponent
	UPROPERTY(VisibleAnywhere)
	class USceneComponent* Root;

	// 2. 총 Mesh의 본체가 될 Mesh Component
	UPROPERTY(VisibleAnywhere)
	class UMeshComponent* Mesh;

	// 3. Effect가 될 Particle System 
	UPROPERTY(EditAnywere)
	class UParticleSystem* MuzzleFlash;
	
	UPROPERTY(EditAnywere)
	class UParticleSystem* ImactEffects;
};
1. USceneComponent* Root : Gun Actor의 Root 컴포넌트를 USceneComponent 타입으로 선언합니다.
2. UMeshComponent* Mesh : Gun Actor의 Mesh 컴포넌트들 UMeshComponent 타입으로 선언합니다.
3. UParticleSystem* MuzzleFlash or ImpactEffect : Gun Actor의 Effect들을 UParticleSystem 타입으로 선언합니다.
* USceneComponent?

- Scene Component는 Actor Component 중 하나로 World의 특정 물리적 위치에 존재합니다. 
  그리고, 그 위치는 Transform(위치, 회전, 스케일)으로 정의됩니다. 더불어, tree를 형성하여
  다른 Scene Component와 Attach 할 수 있는 기능을 제공합니다. 따라서, Actor들은 Scene
  Component를 "Root" 컴포넌트로 설정하여 Actor의 Transform 정보를 얻어올 수 있습니다. 

 

"Scene Component"가 제공하는 주요 기능은 "Attachment" 기능입니다.

오직 "Scene Component"와 "Scene Component"의 하위 클래스들만 "Attachment"가 가능합니다.

 

우리는 "Attachment" 기능의 "Transform(위치, 회전, 스케일)" 정보를 통해 부모 컴포넌트와 자식 컴포넌트 간의 공간적 관계(Spatial Relationship)를 설명할 수 있습니다.

 

4. 각 Component들을 "Attach" 합니다.

// Gun 클래스의 생성자 내부
AGun::AGun()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
	SetRootComponent(Root);

	Mesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Mesh"));
	Mesh->SetupAttachment(Root);
}
1. T CreateDefaultSubobject< typename T > (FName SubobjectName, bool bTransient = false)
: 템플릿 메서드로, Component 혹은 Subobject를 생성합니다.

2. bool AActor::SetRootComponent(USceneComponent* NewRootComponent)
: 루트 컴포넌트를 특정 Scene Component로 지정합니다.

3. void USceneComponent::SetupAttachment(class USceneComponent* InParent, FName InSocketName)
: 생성자에서 활용되며 아직 등록되지 않은 Component를 "Attach"할 부모 컴포넌트를 지정합니다.

 

'게임개발 > Unreal C++' 카테고리의 다른 글

[Unreal]#8_Attach Gun Actor to Shooter Character  (0) 2022.08.16
[Unreal]#7_Spawn Gun Actor in Runtime  (0) 2022.08.12
[Unreal]#5_Character의 이동 속도와 각도 구하기, Animation Blueprint  (0) 2022.08.10
[Unreal]#4_Animation Blueprint, Gameplay와 Animation 연결하기  (0) 2022.08.08
[Unreal]#3_Character Animation, Animation Blueprint, Animation Blend Space  (0) 2022.08.07
  1. [Unreal]#6_Gun Actor Setting
'게임개발/Unreal C++' 카테고리의 다른 글
  • [Unreal]#8_Attach Gun Actor to Shooter Character
  • [Unreal]#7_Spawn Gun Actor in Runtime
  • [Unreal]#5_Character의 이동 속도와 각도 구하기, Animation Blueprint
  • [Unreal]#4_Animation Blueprint, Gameplay와 Animation 연결하기
Hardii2
Hardii2
Hardii2
개발 블로그
Hardii2
전체
오늘
어제
  • 분류 전체보기
    • 알고리즘
    • 웹 개발
      • Node.js
      • React
    • 게임개발
      • DirectX12
      • 관련 지식
      • Unreal C++
      • Unreal 블루프린트
    • 언어
      • Effective C++
      • Basic C++
      • 디자인 패턴
      • 자료구조
      • 기술 질문
    • 문제 풀이
      • BOJ 문제 풀이
      • Programmers 문제 풀이
      • geeksForgeeks 문제 풀이
    • 수학
      • 확률과 통계
      • 게임수학
    • 개인프로젝트
    • 그룹프로젝트
      • PM
      • Dev
    • Github

블로그 메뉴

  • 홈
  • 글쓰기

공지사항

인기 글

태그

  • Effective C++
  • DP
  • stl
  • BOJ
  • unreal
  • 정렬
  • 우선순위 큐
  • programmers
  • 디자인 패턴
  • C++
  • 개발
  • 최단 경로
  • set
  • 알고리즘
  • BFS
  • 기술 질문
  • 그래프
  • Unreal Blueprint
  • dfs
  • 트리

최근 댓글

최근 글

hELLO · Designed By 정상우.v4.2.2
Hardii2
[Unreal]#6_Gun Actor Setting
상단으로

티스토리툴바

개인정보

  • 티스토리 홈
  • 포럼
  • 로그인

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.