I have a custom C++ class named UHandsAnimInstance :
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;
}
It has some custom properties inside and it is the parent class of an animation blueprint asset as you can see in this picture:
And it is located in this location: "/Game/SensorialXR/Blueprints/Gestures/RightHand"
Asset Location in Content Manager
My main problem is that I want to select that object from Content Manager so first I try to put that as a property in another class (AActor class):
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<UHandsAnimInstance*> gestureData;
But I cannot select any object in the editor selector:
So I tried to load all assets from a FString parameter that is the path of all UHandsAnimInstance at runtime using this code in the BeginPlay function inside the custom AActor class:
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)
}
}
The problem is that the class of the obtained asset is UAnimBlueprint (that is why I cast that asset to that type):
Main class of the obtained asset
But I cannot do anything neither get the UHandsAnimInstance object from that asset:
Data from the UAnimBlueprint obtained variable
So, what can I do to get the data I want of my custom C++ class from a blueprint object in the content manager?
The Assets within the Content Browser are not real "instances" of those Objects.
If you want to be able to select the Asset Type from the Content Browser and input it into a Property, you will be required to use a TSubclassOf<UHandsAnimInstance>
type.
This will give you a UClass*
to the Asset Type. Keep in mind this is not an instance. If you want to access default property data on that Type you can use its CDO (Class Default Object). The CDO can be accessed directly from the UClass*
.
UHandsAnimInstance* MyHandsAnimCDO = Cast<UHandsAnimInstance>(MyClass->GetDefaultObject());
The above CDO will require casting to your particular type. Then you can access any Property Default values from there. Do not modify or call non-const functions on the CDO, it is not design to be mutable in the general sense as it is only the template Object from which real instances are generated with at runtime.
If you are looking for a specific instance of your UHandsAnimInstance
you will need to find the associated Skeletal Mesh that it has been instantiated with.