인생언리얼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() 함수 선언은 지워주고
'언리얼게임프로젝트 > TPS C++' 카테고리의 다른 글
Character 이동기능 옮기기 ActorComponent (0) | 2025.04.01 |
---|---|
플레이어 이동 컴포넌트 제작 (0) | 2025.04.01 |
Actor Class 검색 방법, EnemyManager, EnemyFactory (0) | 2025.04.01 |
프로젝트 준비하기 UClass, UObject, CDO (0) | 2025.03.25 |