[C++] 언리얼 기본 이벤트

Woogle·2022년 9월 6일
0

언리얼 엔진 5

목록 보기
3/59
post-thumbnail

기본 이벤트

언리얼에서 클래스를 생성했을 때 자동으로 생성되는 함수들.
일반적으로는 생성자, BeginPlay(), Tick()의 세 가지가 있다.

UCLASS()
class MEDICI_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;
   
};

📄 생성자

클래스가 생성될 때 한번 호출.
초기값 설정할 때에도 사용할 수 있다.
Tick의 활성화/비활성화 여부도 설정한다.

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

📄 BeginPlay

게임이 시작되거나 월드에 스폰되었을 때 호출.
다이나믹 델리게이트를 바인딩할 때에도 사용한다. AddDynamic( UserObject, FuncName ))

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

📄 Tick

매 프레임마다 호출.
Tick이 불필요한 오브젝트의 경우 전체 주석 처리하면 최적화에 도움이 된다.

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

참고 자료

profile
노력하는 게임 개발자

0개의 댓글