【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")
    


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM