【UE4 C++】关卡切换、流关卡加载卸载、退出游戏
基于 UGameplayStatics::
OenLevel
UGameplayStatics::OpenLevel(GetWorld(), TEXT("NewMap"));
OpenLevelBySoftObjectPtr
FSoftObjectPath NewMapPath(TEXT("World'/Game/CPPFunction/Interface/NewMap.NewMap'")); TSoftObjectPtr<UWorld> NewMap(NewMapPath); UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), NewMap);
获取当前关卡名
GetCurrentLevelName
UKismetSystemLibrary::PrintString(GetWorld(), UGameplayStatics::GetCurrentLevelName(GetWorld()));
异步加载关卡
流关卡
基于 UGameplayStatics::
加载
UGameplayStatics::LadStreamLevel
static void LoadStreamLevel(const UObject* WorldContextObject, FName LevelName, bool bMakeVisibleAfterLoad, bool bShouldBlockOnLoad, FLatentActionInfo LatentInfo);
UGameplayStatics::LoadStreamLevelBySoftObjectPtr
static void LoadStreamLevelBySoftObjectPtr(const UObject* WorldContextObject, const TSoftObjectPtr<UWorld> Level, bool bMakeVisibleAfterLoad, bool bShouldBlockOnLoad, FLatentActionInfo LatentInfo);
卸载
UnloadStreamLevel
static void UnloadStreamLevel(const UObject* WorldContextObject, FName LevelName, FLatentActionInfo LatentInfo, bool bShouldBlockOnUnload);
UnloadStreamLevelBySoftObjectPtr
static void UnloadStreamLevelBySoftObjectPtr(const UObject* WorldContextObject, const TSoftObjectPtr<UWorld> Level, FLatentActionInfo LatentInfo, bool bShouldBlockOnUnload);
获取流关卡
GetStreamingLevel
static class ULevelStreaming* GetStreamingLevel(const UObject* WorldContextObject, FName PackageName);
退出游戏
ConsoleCommand,以此类推,可以执行多种命令行
UGameplayStatics::GetPlayerController(GWorld, 0)->ConsoleCommand("quit")