상세 컨텐츠

본문 제목

Actor 클래스

개발기록/개발스터디

by 도리(Dory) 2024. 1. 31. 17:19

본문

Actor

Level 에 올릴 수 있는 클래스

 

Header 파일

클래스를 선언하고, 클래스에 속하는 변수와 함수의 원형을 선언하는 용도의 파일.

 

 

Actor 클래스 내 함수들

 

1) 생성자

클래스가 생성될 때 호출.

클래스 이름이랑 같음.

변수 set 해줌.

 

2) BeginPlay()

Actor 가 배치된 월드에서 게임이 시작되거나, Actor가 월드에 Spawn 되었을 때 한 번 호출됨.

게임 플레이 로직을 초기화 시키는데 사용됨.

 

3) Tick()

매 프레임마다 한 번씩 호출.

DeltaTime 매개변수로 Tick 함수가 얼마 시간을 두고 다시 호출되었는지 측정이 가능하다.

Actor가 살아있는 동안 계속 호출됨.

게임 로직을 주로 여기서 처리.

게임 퍼포먼스 향상을 위해 필요없다면 제거해주는 것이 좋음.

 

 

 

MyActor.h

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

#pragma once

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

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

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

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

};

 

 

MyActor.cpp

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


#include "MyActor.h"

// 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;

}

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

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

}

 

 

 

 

 

PrimaryActorTick.bCanEverTick = true;

Tick함수를 매프레임 호출할 것인지에 대한 설정.

 

 

 

로그찍는 방법 

UE_LOG(LogTemp, Log, TEXT("Tick"));

 

(출처 : 베르의 게임개발 유튜브, https://youtu.be/DkJqLIpSvik?si=tjjMtwpYys_clVN2)

관련글 더보기