【发布时间】:2021-06-07 14:01:53
【问题描述】:
我有一个名为 UHandsAnimInstance 的自定义 C++ 类:
UCLASS(transient, Blueprintable, hideCategories = AnimInstance, BlueprintType)
class SENSORIALSDK_API UHandsAnimInstance : public UAnimInstance
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Fingers)
bool isRight = true;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Fingers)
FRotator wrist;
}
它内部有一些自定义属性,它是动画蓝图资产的父类,如图所示:
而且它位于这个位置:“/Game/SensorialXR/Blueprints/Gestures/RightHand”
Asset Location in Content Manager
我的主要问题是我想从 Content Manager 中选择该对象,所以首先我尝试将其作为属性放在另一个类(AActor 类)中:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<UHandsAnimInstance*> gestureData;
但我无法在编辑器选择器中选择任何对象:
所以我尝试使用自定义 AActor 类中 BeginPlay 函数中的以下代码,从一个 FString 参数加载所有资产,该参数是运行时所有 UHandsAnimInstance 的路径:
FString gesturesPath = "/Game/SensorialXR/Blueprints/Gestures/RightHand";
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
TArray<FAssetData> AssetData;
AssetRegistryModule.Get().GetAssetsByPath(FName(*gesturesPath), AssetData);
for (int i = 0; i < AssetData.Num(); i++) {
UAnimBlueprint* animx = Cast<UAnimBlueprint>(AssetData[i].GetAsset());
if (animx) {
//Do Something (like add to the gestureData list)
}
}
问题在于获得的资源的类是 UAnimBlueprint(这就是我将该资源转换为该类型的原因):
Main class of the obtained asset
但我无法从该资产中获取 UHandsAnimInstance 对象:
Data from the UAnimBlueprint obtained variable
那么,如何从内容管理器中的蓝图对象中获取我想要的自定义 C++ 类的数据?
【问题讨论】:
标签: c++ unreal-engine4 unreal-blueprint