[UE5 / C++] ๐Ÿ’จ ์•กํ„ฐ ์›€์ง์ด๊ธฐ (1)

Singery00ยท2024๋…„ 4์›” 18์ผ
0

UE5 C++

๋ชฉ๋ก ๋ณด๊ธฐ
6/20
post-thumbnail

๊ฐœ์š”

๐Ÿ’ก C++๋กœ ์•กํ„ฐ์˜ Transform์„ ์กฐ์ž‘ํ•ด๋ณด์ž.

C++์„ ์‚ฌ์šฉํ•ด์„œ ๋ ˆ๋ฒจ์— ๋ฐฐ์น˜ํ•œ ์•กํ„ฐ๋ฅผ ์›€์ง์—ฌ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

1. C++ ์ฝ”๋“œ๋กœ ์•กํ„ฐ ์ƒ์„ฑ
2. ์•กํ„ฐ Transfrom ์กฐ์ •
3. ์•กํ„ฐ ํšŒ์ „ ๊ฐœ์„ 

๋ณธ๋ก 

์ด๋ฒˆ์—๋Š” C++๋กœ ์•กํ„ฐ์—๊ฒŒ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ ,
Transform์„ ์กฐ์ ˆํ•ด์„œ ๋ ˆ๋ฒจ์—์„œ ๊ฐ€์ง€๊ณ  ๋†€์•„ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

์žฌ๋ฐŒ๋Š” ์žฅ์• ๋ฌผ๋“ค์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์„ ๊ฒ๋‹ˆ๋‹ค.

C++ ํด๋ž˜์Šค ์ƒ์„ฑํ•˜๊ธฐ

MyActor๋กœ ์ƒ์„ฑํ•ด์ค„๊ฒŒ์š”.

์•กํ„ฐ์— ์ปดํฌ๋„ŒํŠธ ์ถ”๊ฐ€

๋ธ”๋ฃจ ํ”„๋ฆฐํŠธ์—์„  ์ปดํฌ๋„ŒํŠธ์— Addํ•˜๋Š” ๊ณผ์ •์ž…๋‹ˆ๋‹ค.

ํ•„์š”ํ•œ ์ปดํฌ๋„ŒํŠธ ์„ ์–ธ

Static Mesh Component๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•ด์ฃผ๊ฒ ์Šต๋‹ˆ๋‹ค.

UCLASS()
class MYPROJECT_API AMyActor : public AActor
{
	GENERATED_BODY()
	
	// ์ƒ๋žต
    
public:
	UPROPERTY(VisibleAnywhere,Category=MyValue)
	class UStaticMeshComponent* staticMesh;

};

์ƒ์„ฑ์ž ํ•จ์ˆ˜์—์„œ ์ดˆ๊ธฐํ™”

Static Mesh Component ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์ฃผ๊ณ ,
Root Component์˜ ํ•˜์œ„์š”์†Œ๋กœ ๋„ฃ์–ด ์ฃผ๊ฒ ์Šต๋‹ˆ๋‹ค.

AMyActor::AMyActor()
{
 	// 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;

	staticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
	staticMesh->SetupAttachment(RootComponent);
}

Cube๋กœ Mesh ์ง€์ •ํ•˜๊ธฐ

๋ธ”๋ฃจํ”„๋ฆฐํŠธ์˜ Details์—์„œ ์‹ค์ œ Static Mesh๋ฅผ ํ• ๋‹นํ•˜๋Š” ๊ณผ์ •์ž…๋‹ˆ๋‹ค.

Cube ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

๋จผ์ € ์–ธ๋ฆฌ์–ผ ์—๋””ํ„ฐ์—์„œ Static Mesh ํ๋ธŒ์˜ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ๋ณต์‚ฌํ•ด์„œ ๊ฐ€์ ธ์˜ค๊ฒ ์Šต๋‹ˆ๋‹ค.
๊ฒ€์ƒ‰ํ•ด์„œ ๋งˆ์Œ์— ๋“œ๋Š” ๊ฑธ๋กœ ๊ฐ€์ ธ์™€ ์ฃผ์„ธ์š”

ConstructorHelpers์˜ FObjectFinder๋ฅผ ํ†ตํ•ด ํ• ๋‹นํ•  Static Mesh๋ฅผ ์ฐพ์•„ ์˜ต๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  Text ์•ˆ์— Cube์˜ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ๋„ฃ์–ด ์ฃผ์„ธ์š”.

// Sets default values
AMyActor::AMyActor()
{
 	// 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;

	staticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
	staticMesh->SetupAttachment(RootComponent);

	// ์ฝ”๋“œ ์ถ”๊ฐ€
	ConstructorHelpers::FObjectFinder<UStaticMesh> cubeMesh(TEXT("/Script/Engine.StaticMesh'/Game/StarterContent/Shapes/Shape_Cube'"));

}

Cube ํ• ๋‹นํ•˜๊ธฐ

cubeMesh ํ˜ธ์ถœ์ด ์„ฑ๊ณตํ•˜๋ฉด SetStaticMesh์„ ํ†ตํ•ด ํ• ๋‹นํ•ด์ค๋‹ˆ๋‹ค.

// Sets default values
AMyActor::AMyActor()
{
 	// 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;

	staticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
	staticMesh->SetupAttachment(RootComponent);

	ConstructorHelpers::FObjectFinder<UStaticMesh> cubeMesh(TEXT("/Script/Engine.StaticMesh'/Game/StarterContent/Shapes/Shape_Cube'"));

	// ์ฝ”๋“œ ์ถ”๊ฐ€
	if (cubeMesh.Succeeded())
	{
		staticMesh->SetStaticMesh(cubeMesh.Object);
	}

}

MyActor.cpp๋กœ BP์ƒ์„ฑ

โ—์ €์žฅ ํ›„ ์‹คํ–‰โ—ํ•˜๊ณ  Class๋ฅผ ์šฐํด๋ฆญํ•ด์„œ Blueprint๋กœ ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”.

์ ์šฉ ํ™•์ธ

๊ฐ๊ฐ์˜ ๋ฐฉ๋ฒ•์œผ๋กœ ์‹ค์ œ๋กœ StaticMesh์— ํ๋ธŒ๊ฐ€ ํ• ๋‹น๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

BP์˜ Viewport์—์„œ ํ™•์ธ

Viewport์— ํ๋ธŒ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค!

๋ ˆ๋ฒจ์— ๋ฐฐ์น˜ํ•ด์„œ ํ™•์ธ

์‹ค์ œ๋กœ ๋ ˆ๋ฒจ์— ๋ฐฐ์น˜ํ•ด๋„ ํ๋ธŒ๊ฐ€ ์žˆ๋Š”๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ ˆํผ๋Ÿฐ์Šค ์ด์Šˆ ์‚ฌํ•ญ

์•„๊นŒ ์šฐ๋ฆฌ๊ฐ€ ํ๋ธŒ์˜ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ๋ณต์‚ฌํ•ด์„œ TEXT์— ํ• ๋‹น ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋Ÿฐ๋ฐ ๋ณต์‚ฌํ•œ ๊ฒฝ๋กœ๋ฅผ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
/Script/Engine.StaticMesh'/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube'

๊ฐ€์žฅ ๋’ค๋ฅผ ๋ณด๋ฉด /Shapes/Shape_Cube.Shape_Cube๋กœ ์ด๋ฆ„์ด 2๋ฒˆ ์žˆ์Šต๋‹ˆ๋‹ค!
์™ ์ง€ ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ ์ด ์ƒํƒœ๋กœ ๊ทธ๋Œ€๋กœ ์ปดํŒŒ์ผํ•˜๋ฉด ํ˜ธ์ถœ์— ์‹คํŒจํ•˜๊ฒŒ ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ ์ด๋ฆ„์„ ํ•œ๋ฒˆ ์ง€์šด ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ์‚ฌ์šฉํ•ด์ฃผ๋ฉด ํ•ด๋‹น ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋ฉ๋‹ˆ๋‹ค.

์ด๋ ‡๊ฒŒ ๋ง์ด์ฃ 
/Script/Engine.StaticMesh'/Game/StarterContent/Shapes/Shape_Cube'


๋งˆ๋ฌด๋ฆฌ

์ด๊ฒƒ์œผ๋กœ Static Mesh Component์— ํ๋ธŒ๋ฅผ C++์ฝ”๋“œ๋กœ ์ ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„ ๋ณด์•˜์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ์—” ํ•ด๋‹น ์•กํ„ฐ์˜ Transform์š”์†Œ๋ฅผ ์กฐ์ž‘ํ•˜์—ฌ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

1. C++ ์ฝ”๋“œ๋กœ ์•กํ„ฐ ์ƒ์„ฑ
2. ์•กํ„ฐ Transfrom ์กฐ์ •
3. ์•กํ„ฐ ํšŒ์ „ ๊ฐœ์„ 

profile
๊ฒŒ์ž„ ๊ฐœ๋ฐœ์ž๊ฐ€ ๋˜์–ด๋ณด์ž

0๊ฐœ์˜ ๋Œ“๊ธ€