关于UE4动态资源加载(蓝图类)

来源:互联网 发布:mac打不开百度 编辑:程序博客网 时间:2024/04/28 14:20

本帖纯属个人原创,如有转载请注明出处

需要注意的几点:

1.调试环境下进行的资源加载方式到打包出来后不一定能够使用。

2.假如遇到调试模式下程序运行正常,但是打包出来后程序crash,可以查看log: Saved/Logs/filename/log

3.资源路径的代码书写格式 

map : "Game/Maps/Main.map"

蓝图类 :  "Game/Blueprint/Skill/skill_1.skill_1_C"

正常的uasset: "Game/Bluerpint/Sound/sound_1.sound_1"


通过摸索,check到如下代码:

UBlueprintGeneratedClass* FileName::GetAssetFromPath(FString AssetPath)
{
UBlueprintGeneratedClass *ParentClass = nullptr;
FStringClassReference ref = AssetPath;
UObject* uoTmp = ref.ResolveObject();
if (uoTmp == nullptr)
{
UE_LOG(LogTemp, Log, TEXT("GetAssetFromPath path = %s", *AssetPath));
FStreamableManager EKAssetLoader;
uoTmp = EKAssetLoader.SynchronousLoad(ref);
}


ParentClass = Cast<UBlueprintGeneratedClass>(uoTmp);


return ParentClass;
}


外部不管是spawnActor或者是NewObject直接传入ParentClass。



如有错误还请纠正。

0 0