관리 메뉴

Mini

블루프린트 클래스 본문

UE5

블루프린트 클래스

Mini_96 2022. 8. 11. 11:43

* CPP to BluePrint

 

BUT) BP는 CPP보다 10배 느리므로 남발하지 마라.

BP사용 => 주로 프로토타입

CPP사용 => 성능중요한 곳

// Fill out your copyright notice in the Description page of Project Settings.


#include "MyCharacter.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"

// Sets default values
AMyCharacter::AMyCharacter()
{
 	// Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm"));
	Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));

	SpringArm->SetupAttachment(GetCapsuleComponent());
	Camera->SetupAttachment(SpringArm);

	SpringArm->TargetArmLength = 500.f;
	SpringArm->SetRelativeRotation(FRotator(-35.0f, 0.f, 0.f));

	GetMesh()->SetRelativeLocationAndRotation(
		FVector(0.f, 0.f, -88.f), FRotator(0.f, -90.f, 0.f));


	static ConstructorHelpers::FObjectFinder<USkeletalMesh> SM(TEXT("SkeletalMesh'/Game/ParagonGreystone/Characters/Heroes/Greystone/Meshes/Greystone.Greystone'"));

	if (SM.Succeeded())
		GetMesh()->SetSkeletalMesh(SM.Object);


}

// Called when the game starts or when spawned
void AMyCharacter::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AMyCharacter::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	PlayerInputComponent->BindAxis(TEXT("UpDown"), this, &AMyCharacter::UpDown);
	PlayerInputComponent->BindAxis(TEXT("LeftRight"), this, &AMyCharacter::LeftRight);
	PlayerInputComponent->BindAxis(TEXT("Yaw"), this, &AMyCharacter::Yaw);

}

void AMyCharacter::UpDown(float Value)
{
	if (Value == 0.f) return;
	//UE_LOG(LogTemp, Warning, TEXT("UpDown %f"), Value);
	AddMovementInput(GetActorForwardVector(), Value);
}

void AMyCharacter::LeftRight(float Value)
{
	if (Value == 0.f) return;
	//UE_LOG(LogTemp, Warning, TEXT("LeftRight %f"), Value);
	AddMovementInput(GetActorRightVector(), Value);
}

void AMyCharacter::Yaw(float Value)
{
	AddControllerYawInput(Value);
}

 

변수명, 함수명은 거의 그대로 -> 그대로 찾아서 연결해주면 된다

 

- GameMode에서 기본Pawn을 BP캐릭터로 바꿔준다.

//기본생성자
AMyGameModeBase::AMyGameModeBase()
{
	//DefaultPawnClass = AMyCharacter::StaticClass();

	//FClassFinder생성자(찾을클래스)
	static ConstructorHelpers::FClassFinder<ACharacter>
		BP_Char(TEXT("Blueprint'/Game/BluePrints/BP_MyCharacter.BP_MyCharacter_C'"));

	if (BP_Char.Succeeded())
		DefaultPawnClass = BP_Char.Class;


}

BP는 경로뒤에_C를 써야함.(규칙임)

 

 

* BP_MyCharacter2 상속 MyCharater, BP_MyGameMode

내가 만든 클래스도 상속가능함.

CPP파일 : UI에서 Mesh변경=> (-) 1회용임. 계속적용X

vs

BP : CPP로 클래스를 만드는 것과 같음 =>  : UI에서 Mesh변경=>  계속적용(O)

 

- BP로 게임모드 만들기

(+) : GameMode는 자주변경됨 -> BP로 만들면 편리하게 변경가능.

월드세팅에서 BP_GameMode로 설정.

 

'UE5' 카테고리의 다른 글

스테이트 머신  (0) 2022.08.14
애니메이션 기초  (0) 2022.08.14
캐릭터 생성  (0) 2022.08.08
게임플레이 프레임워크  (0) 2022.08.07
로그와 디버깅  (0) 2022.08.07