[UE4]一些实用方法

UE singleton 单例实现方法总结

https://blog.csdn.net/cartzhang/article/details/82764433

 

LNK2019 FAssetEditorManager

https://blog.csdn.net/luofeixiongsix/article/details/79966989

UE4 自定义Asset

https://blog.csdn.net/shidya/article/details/71553360

FModuleManager::LoadModulePtr

 

https://docs.unrealengine.com/en-us/Programming/Assets/Registry

 

动态加载流关卡

UWorld* PersistentWorld = GetWorld();

 

if (!PersistentWorld)

{

    UE_LOG(LogTemp, Fatal, TEXT("UDynamicLevels::LoadTileToStreamingArray >> Invalid PersistentWorld!!!"));

    return;

}

 

//new StreamingClass Instance 新流关卡实例

UClass* StreamingClass = ULevelStreamingKismet::StaticClass();

ULevelStreaming* StreamingLevel = Cast(StaticConstructObject(StreamingClass, PersistentWorld, NAME_None, RF_Transient, NULL));

 

// FName PackageName = TEXT("/Game/TempUmap/Level_01") 根据项目实际情况获取并设置PackageName

StreamingLevel->SetWorldAssetByPackageName(PackageName);

 

//Make New Level Visible 使流关卡可见

StreamingLevel->bShouldBeLoaded = true;

StreamingLevel->bShouldBeVisible = true;

StreamingLevel->bShouldBlockOnLoad = false;

 

//Very Important, used by LevelStreaming* to load the map 设置流关卡的包名

StreamingLevel->PackageNameToLoad = PackageName;

//Add to UWorld 将流关卡添加到World中

PersistentWorld->StreamingLevels.Add(StreamingLevel);
 

 

 

void AEngineTestActor::WorldSettings()
{
    EditorWorld = InitWorld();

    EditorWorld->GetWorldSettings()->bEnableWorldComposition = true;
    EditorWorld->GetWorldSettings()->bEnableAISystem = true;
    EditorWorld->GetWorldSettings()->bEnableHierarchicalLODSystem = true;


    FStreamableManager& Streamable = UAssetManager::GetStreamableManager();
    FSoftObjectPath AssetRef = FSoftObjectPath(TEXT("Blueprint'/Game/MyLODSetup.MyLODSetup'"));
    TSoftClassPtr LODAsset = TSoftClassPtr(AssetRef);
    EditorWorld->GetWorldSettings()->HLODSetupAsset = LODAsset;


    ShowFcopeTask(FText::FromString(TEXT("PreviewBuild")));
    EditorWorld->HierarchicalLODBuilder->ClearHLODs();
    EditorWorld->HierarchicalLODBuilder->PreviewBuild();
    ShowFcopeTask(FText::FromString(TEXT("BuildMeshesForLODActors")));
    EditorWorld->HierarchicalLODBuilder->BuildMeshesForLODActors(true);
}

UWorld * AEngineTestActor::InitWorld()
{
    check(GEngine);
    UWorld* World = nullptr;
    for (const FWorldContext& Context : GEngine->GetWorldContexts())
    {
        UWorld* ThisWorld = Context.World();
        if (!ThisWorld || (Context.WorldType == EWorldType::PIE))
        {
            continue;
        }
        else if (Context.WorldType == EWorldType::Editor)
        {
            World = ThisWorld;
        }
    }
    //
    return World;
}

 

你可能感兴趣的:([UE4]一些实用方法)