【问题标题】:Is there any way to get the class data from the animation blueprint asset obtained from the Content Manager?有没有办法从内容管理器获取的动画蓝图资源中获取类数据?
【发布时间】: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;
}

它内部有一些自定义属性,它是动画蓝图资产的父类,如图所示:

Blueprint Animation Editor

而且它位于这个位置:“/Game/SensorialXR/Blueprints/Gestures/RightHand”

Asset Location in Content Manager

我的主要问题是我想从 Content Manager 中选择该对象,所以首先我尝试将其作为属性放在另一个类(AActor 类)中:

UPROPERTY(EditAnywhere, BlueprintReadWrite)
    TArray<UHandsAnimInstance*> gestureData;

但我无法在编辑器选择器中选择任何对象:

Editor Selector Example

所以我尝试使用自定义 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


    【解决方案1】:

    内容浏览器中的资产不是这些对象的真实“实例”。

    如果您希望能够从内容浏览器中选择资产类型并将其输入到属性中,则需要使用TSubclassOf&lt;UHandsAnimInstance&gt; 类型。

    这将为您提供资产类型的UClass*。请记住,这不是一个实例。如果要访问该类型的默认属性数据,可以使用其 CDO(类默认对象)。 CDO 可以直接从UClass* 访问。

    UHandsAnimInstance* MyHandsAnimCDO = Cast&lt;UHandsAnimInstance&gt;(MyClass-&gt;GetDefaultObject());

    上述 CDO 需要转换为您的特定类型。然后您可以从那里访问任何属性默认值。不要在 CDO 上修改或调用非常量函数,它不是一般意义上的可变函数,因为它只是在运行时生成真实实例的模板对象。

    如果您正在寻找 UHandsAnimInstance 的特定实例,您需要找到已实例化的关联骨架网格体。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-07
      • 1970-01-01
      • 2022-06-10
      • 2015-10-18
      • 1970-01-01
      • 2011-09-25
      • 2010-09-12
      • 1970-01-01
      相关资源
      最近更新 更多