【UE4 C++】关卡切换、流关卡加载卸载、退出游戏
切换关卡
基于 UGameplayStatics::
-
OpenLevel
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")
作者:砥才人
出处:https://www.cnblogs.com/shiroe
本系列文章为笔者整理原创,只发表在博客园上,欢迎分享本文链接,如需转载,请注明出处!