【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")
    
posted @ 2021-05-07 23:27  砥才人  阅读(4286)  评论(2编辑  收藏  举报