UE学习记录10----C++通过软路径获取类资产

文章介绍了如何通过FStringUPR_AssetPath_Library中的函数处理UE编辑器中的资产路径,包括转换Actor、纹理和材质的类路径,以及Object派生类的加载。
摘要由CSDN通过智能技术生成

软路径通过ue 编辑器找到对应资产复制软路径 

//Actor等资产需要在类名后添加_C
FString UPR_AssetPath_Library::GetAssetPath_C(const FString& Path)
{
	if (Path.IsEmpty()) return TEXT("");

	FString inPath = *Path;
	TArray<FString> PathItems;

	inPath.ParseIntoArray(PathItems, TEXT("'"));
	if (PathItems.Num() == 1)
	{
		return inPath;
	}
	else if (PathItems.Num() > 1)
	{
		inPath = PathItems[1] + "_C";
	}
	return inPath;
}

//Actor类名
UClass* GetActorClassFromPath(const FString& Path)
{
	FString inPath = GetAssetPath_C(Path);
	if (inPath.IsEmpty()) return NULL;

	const FSoftClassPath ClassPath = FSoftClassPath(inPath);
	UClass* ActorClass = ClassPath.TryLoadClass<AActor>();
	return ActorClass; /*LoadClass<AActor>(NULL, *Path);*/
}

//纹理
UTexture2D* GetTextureFromPath(const FString& Path)
{
	return Cast<UTexture2D>(StaticLoadObject(UTexture2D::StaticClass(), NULL, *Path));
}

//材质
UMaterialInterface* GetMaterialBySoftPath(const FString& SoftPath)
{
	return Cast<UMaterialInterface>(StaticLoadObject(UMaterialInterface::StaticClass(), NULL, *SoftPath));
}

//Object派生的类名
UClass* GetActorClassFromPath(const FString& Path)
{
	if (Path.IsEmpty()) return NULL;
	const FSoftClassPath ClassPath = FSoftClassPath(Path);
	UClass* objectClass = ClassPath.TryLoadClass<UObect>();
	return objectClass ; 
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值