Accessing C++ 'Native class' and it's variables from a UBlueprint object

I am trying to check the values of the C++ ‘Native Class’ of a Blueprint object, in C++ code. I am working with a derived EditorValidator_Base class. I want to validate that my blueprinted MyGameplayAbility objects have certain fields set properly (ex: duration = 0 for duration policy of instant, positive magnitude values for healing abilities, etc).

CanValidateAsset_Implementation works as intended as I check for the passed asset’s class to be UBlueprint and that asset’s parent class is equal to MyGameplayAbility.

Within ValidateLoadedAsset_Implementation is where I want to access the values within the MyGameplayAbility class of the asset I am validating, but I cannot find any way to do this.

Is this something where I am missing the forest for the trees or is this actually a problem process?

Sounds like you want to cast the InAsset parameter to your native type:

UMyGameplayAbility* Ability = Cast<UMyGameplayAbility>(InAsset);

Or am I misunderstanding?

The object is a UBlueprint of the UMyGameplayAbility class. If I cast directly to UMyGameplayAbility, it fails. While it is possible to use a UGameplayAbility class (or derived class) directly as this asset type, this sacrifices the functionality of blueprints for special abilities and removes the need to manually code every exception.

try accessing it via

UBlueprint* Bp = Cast<UBlueprint>(InAsset);
UClass* Class = Bp->GeneratedClass;
UObject* CDO = Class->GetDefaultObject();
UMyGameplayAbility Ability = Cast<UMyGameplayAbility>(CDO);

You might want to validate each step with a check

That did it and thank you!

EDataValidationResult UEditorValidator_GameplayAbilities::ValidateLoadedAsset_Implementation(UObject* InAsset, TArray<FText>& ValidationErrors)
{
    UBlueprint* InBlueprint = Cast<UBlueprint>(InAsset);
    UMyGameplayAbility* Instance = Cast<UMyGameplayAbility>(InBlueprint->GeneratedClass->GetDefaultObject());

    // validation steps/logic here
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.