[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<ULevelStreaming>(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<class UHierarchicalLODSetup> LODAsset = TSoftClassPtr<class UHierarchicalLODSetup>(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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值