Cpp에서 레벨 재시작
Cpp에서 레벨을 재시작 하는 방법은 크게 ConsolCommand를 이용하는 것과 UGameplayStatics를 이용하는 2가지가 있다.
ConsolCommand
콘솔 커맨드를 Cpp에서 실행시키는 법은 월드로부터 명령어를 실행하는 GetWorld()->Exec 함수와 플레이어 컨트롤러에서 실행하는 OwingPlayerController->ConsoleCommand 가 있다.
GetWorld()->Exec(GetWorld(), TEXT("RestartLevel"));
OwingPlayerController->ConsoleCommand(TEXT("RestartLevel"));
GetWorld()->Exec 함수의 경우 커맨드가 실행되지 않는다(이유는 잘모르겠다)
OwingPlayerController->ConsoleCommand 로 커맨드를 실행하면 정상적으로 동작한다
UGameplayStatics
UGameplayStatics 를 사용하기 위해선 #include "Kismet/GameplayStatics.h"를 추가 해야된다
UGameplayStatics::OpenLevel(GetWorld(), FName(TEXT("Level_1")));
OpenLevel 함수로 재시작할 레벨의 이름을 넣어주면 해당 레벨을 재시작할 수 있다.
또한 이 함수로는 다른 레벨을 여는것도 가능하다.
'Unreal Engine > Unreal 기초' 카테고리의 다른 글
UnrealEngine 가비지 컬렉션 (0) | 2025.04.01 |
---|---|
UnrealEngine 리플렉션 (0) | 2025.03.31 |
UnrealEnigne Cpp함수를 블루프린트에서 사용 (0) | 2025.02.07 |
UnrealEnigne 헤드업디스플레이 구현 및 초기화 프로세스 (0) | 2024.12.18 |
UnrealEnigne 행동트리(Behavior Tree) 모델 (0) | 2024.11.05 |