본문 바로가기

언리얼게임프로젝트/TPS C++

ActorComponent Movement, InputComponent

 

인생언리얼5 뒷부분에 나오는 부분이다. 기본적으로 앞부분의 프로젝트가 있어야 한다. 인생언리얼5 git에서 다운받을수 있다.

이건 참조부분

 

언리얼 엔진(Unreal Engine) 튜토리얼 - Actor Component로 공전하는 Sphere 만들기

개요Actor와 Actor Component를 가지고 캐릭터 주위를 공전하는 Sphere를 만들어 보자. 튜토리얼에서 배울 수 있는 것들Actor Component를 Actor에 추가하는 방법.물체가 원 운동을 하게 하는 방법.Actor Component

eastroot1590.tistory.com

 

많이 쓰는 기능을 컴포넌트에 모아 놓고 재활용할수 있게 하는 방법이다.

C++클래스를 부모를 액터컴포넌트로 선택하고 이름을 PlayerBaseComponent로 한다.

컴포넌트의 부모가 될 me, MovementComponent의 포인터인 moveComp 변수를 선언

키입력처리를 각각의 컴포넌트에서 담당할수 있게 BeginPlay() 선언밑에 SetupInputBinding() 이름의 함수를 선언 오버라이딩할수 있게 virtual 키워드를 붙여줍니다.

Tick() 함수 선언은 지워주고

#pragma once

#include "CoreMinimal.h"
#include "TPSPlayer.h"
#include <GameFramework/CharacterMovementComponent.h>
#include "Components/ActorComponent.h"
#include "PlayerBaseComponent.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class TPS_API UPlayerBaseComponent : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UPlayerBaseComponent();

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

public:
	virtual void SetupInputBinding(class UEnhancedInputComponent* PlayerInput) {};

public:	
	UPROPERTY()
	ATPSPlayer* me;

	UPROPERTY()
	UCharacterMovementComponent* moveComp;
		
};

Tick() 함수 선언은 지워주고 안쓸기 때문에 생성자에서 false로 해주고

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


#include "PlayerBaseComponent.h"
#include <GameFramework/CharacterMovementComponent.h>

// Sets default values for this component's properties
UPlayerBaseComponent::UPlayerBaseComponent()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = false;

	// ...
}


// Called when the game starts
void UPlayerBaseComponent::BeginPlay()
{
	Super::BeginPlay();

	// ...
	me = Cast<ATPSPlayer>(GetOwner());
	moveComp = me->GetCharacterMovement();
}

Tick() 함수 선언은 지워주고